Esempio n. 1
0
def update(request, id):
    service = Service.objects.get(id=id)
    form = ServiceForm(request.POST, instance=service)
    if form.is_valid():
        form.save()
        return redirect("/show")
    return render(request, 'edit.html', {'service': service})
Esempio n. 2
0
def emp(request):
    if request.method == "POST":
        form = ServiceForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                return redirect('/show')
            except:
                pass
    else:
        form = ServiceForm()
    return render(request, 'index.html', {'form': form})
Esempio n. 3
0
def service_create(request):
    ImageFormset = modelformset_factory(imageService,
                                        fields=('image', ),
                                        labels={'image': ''},
                                        extra=1)
    if request.method == 'POST':
        form = ServiceForm(request.POST)
        formset = ImageFormset(request.POST or None, request.FILES or None)
        if form.is_valid() and formset.is_valid():
            service = form.save(commit=False)
            service.user = request.user
            service.person = request.user.person
            service.save()

            for f in formset:
                try:
                    photo = imageService(service=service,
                                         image=f.cleaned_data['image'])
                    photo.save()

                except:
                    break
            return redirect('list')

    else:
        form = ServiceForm()
        formset = ImageFormset(queryset=imageService.objects.none())
    context = {
        'form': form,
        'formset': formset,
        'user': request.user,
        'person': request.user.person
    }
    return render(request, 'service/new.html', context)
Esempio n. 4
0
def Service(request):
	if request.method=="POST":
		j=ServiceForm(request.POST,request.FILES)
		if j.is_valid():
			i=j.save(commit=False)
			i.uid_id=request.user.id
			i.save()
			return redirect('/showdata')
	j=ServiceForm()
	return render(request,'services/Services.html',{'u':j})