How to populate fields generated by modelformset_factory with data from database

21 views
Skip to first unread message

Michael Klassen

unread,
Aug 7, 2020, 7:47:11 AM8/7/20
to Django users
Hello:

I am using modelformset_factory to generate my form based on a model.  If the user submits a page, then returns to it later, I would like to populate the fields with what they previously answered.  I can only find examples of pre-populated fields with the extra forms; is there a way to do this with the first form?

Thank you.

--michael

Integr@te System

unread,
Aug 7, 2020, 10:24:21 AM8/7/20
to django...@googlegroups.com
Hi Michael,

You can read queryset combine with model in modelformset_factory() method to get exact user and/or any fields you need as existed instance or base on cookies or sth like that to identify your user, depend on your use case(ex trigger events or choose one option...). Hope it helpful.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/75f5f32d-64f7-4a90-a34e-8d1717ff2828o%40googlegroups.com.

Michael Klassen

unread,
Aug 8, 2020, 11:48:13 AM8/8/20
to Django users
Hi, thank you for your response but I need some more specifics.  My queryset includes the questions which the form presents to the user.  How do I get their responses included in the queryset?  Do I have to somehow join tables to get both questions and responses?  If I follow the relationships in the queryset, I see that I can filter and find the responses, but how do I get Django to fill the form fields with the responses?

Thank you!


On Friday, August 7, 2020 at 10:24:21 AM UTC-4, Integr@te System wrote:
Hi Michael,

You can read queryset combine with model in modelformset_factory() method to get exact user and/or any fields you need as existed instance or base on cookies or sth like that to identify your user, depend on your use case(ex trigger events or choose one option...). Hope it helpful.



On Fri, Aug 7, 2020, 6:46 PM Michael Klassen <mjkl...@gmail.com> wrote:
Hello:

I am using modelformset_factory to generate my form based on a model.  If the user submits a page, then returns to it later, I would like to populate the fields with what they previously answered.  I can only find examples of pre-populated fields with the extra forms; is there a way to do this with the first form?

Thank you.

--michael

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Integr@te System

unread,
Aug 8, 2020, 1:43:20 PM8/8/20
to django...@googlegroups.com
Hi Micheal,



You see in doc with example such as custom queryset, initial data get from existed instances all base on your design and codebase.


To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ec084248-7c27-468a-90a3-c2bf5bc3fc20o%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages