Passing Instance to Django formset

一个人想着一个人 提交于 2020-01-03 08:22:13

问题


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)

回答1:


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

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




回答2:


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



来源:https://stackoverflow.com/questions/11666035/passing-instance-to-django-formset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!