inline formset data not save

10 views
Skip to first unread message

Anirban Singha

unread,
Sep 11, 2021, 10:04:32 AMSep 11
to Django users
models.py

class product_list(models.Model):
   date=models.DateTimeField(auto_now_add=True,null=True)
   deal=models.ForeignKey(dealForm, null=True, blank=True , on_delete=models.CASCADE)
   pro_name=models.ForeignKey(wareForm, null=True, on_delete=models.CASCADE)
   pro_quantity=models.IntegerField()
   def __str__(self):
     return self.name


forms.py

class productForm(ModelForm):
   class Meta:
     model=product_list
     fields= '__all__'

views.py
def myproduct(request, pk):
   x=wareForm.objects.all()
   DeliveryFormSet=inlineformset_factory(dealForm, product_list, fields=('pro_name','pro_quantity'), extra=len(x), can_delete=False)
   dealer=dealForm.objects.get(id=pk)
   formset=DeliveryFormSet(queryset= product_list.objects.none() , instance=dealer)
   #date=datetime.datetime.now().strftime("%d-%m-%y")
   if request.method == 'POST':
     formset=DeliveryFormSet(request.POST,instance=dealer)
     print(formset)
     if formset.is_valid():
       for f in formset:
         print ('testing')
       return HttpResponseRedirect('delivery.html')
     else:
       print('hello')
context={'name':'Product list','formset':formset}
return render(request, 'product.html',context)

in this code formset.isvalid is false. BTW i'm beginner

Reply all
Reply to author
Forward
0 new messages