Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Instance to Django formset

How to pass a instance to the Django formset, The Scenario is like this. I have updated multiple rows by using a formset and, in a later stage i need to edit those values which i added earlier.(Editing)

q = PaymentLines.objects.filter(pay_lines=project)
formset = PayFormSet(prefix='payment', instance=q)
like image 608
Ani Varghese Avatar asked Jul 26 '12 09:07

Ani Varghese


2 Answers

AuthorFormSet(queryset=Author.objects.all())

https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#changing-the-queryset

like image 184
Willian Avatar answered Sep 28 '22 06:09

Willian


I have used it as follows the formset used is inlineformset_factory.

q = Projects.objects.get(pk=project)

formset = PayFormSet(prefix='payment',instance=q)

and then pass the formset to the template

like image 23
Ani Varghese Avatar answered Sep 28 '22 07:09

Ani Varghese