def add_buyer_obj(request): if request.method == 'POST': form = BuyerForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/buyers') else: form = BuyerForm() return add_buyer(request, form)
def save_edit_buyer(request): if request.method == 'POST': buyer = Buyer.objects.get(id=request.POST.get('edit')) form = BuyerForm(request.POST, instance=buyer) if form.is_valid(): form.save() return HttpResponseRedirect('/buyers') else: form = BuyerForm() return edit_buyer(request, request.POST.get('edit'))
def add_buyer(request, form=BuyerForm()): form.fields['rieltor'].queryset = UserFullName.objects.filter( is_active=True) form.fields['loyality'].queryset = UserFullName.objects.filter( is_active=True) return render(request, 'homes/add_buyer.html', { 'time': timezone.now(), 'form': form })
def edit_buyer(request, id_buyer): buyer = Buyer.objects.get(id=id_buyer) form = BuyerForm(instance=buyer) form.fields['rieltor'].queryset = UserFullName.objects.filter( is_active=True) form.fields['loyality'].queryset = UserFullName.objects.filter( is_active=True) return render(request, 'homes/add_buyer.html', { 'form': form, 'edit': True, 'id_buyer': id_buyer })