0

I use "msignup" model for user signups. after signup is complete which works just fine, in the profile of the user I want to let them change some basic information that they used during the signup (which are saved in database in msignup model) using modelform named "accountSettingsForm". Obviously the original user information must be there in the "accountSettingsForm " and the user would change any piece of information he/she likes. I know it is possible to set the initial value of the accountSettingsForm:

form = accountSettingsForm(initial={'someFieldName':snomeVariable})

But I assume there is a better way of doing this that I don't know about. Probably using __init__ methods is more appropriate. Any helps will be greatly appreciated.

Hemen
  • 55
  • 1
  • 9
  • Related? http://stackoverflow.com/questions/604266/django-set-default-form-values – rrauenza Jun 20 '16 at 01:28
  • Why don't you think using `initial` is appropriate? – solarissmoke Jun 20 '16 at 03:03
  • @rrauenza definitely related but my question is how to get the initial value from the database dynamicly and not setting the default values for the form. – Hemen Jun 20 '16 at 08:36
  • @solarissmoke It seems verbose! usually Django has some magic which summarizes 10 lines into just two! – Hemen Jun 20 '16 at 08:39
  • @rrauenza When I use initial, since the modelform has a subset of fields of the model, it gives me 'required' error for absent fields that I don't want to update. – Hemen Jun 20 '16 at 10:21
  • You can do it in `__init__`, but you'll still be modifying the `initial` argument. – rrauenza Jun 20 '16 at 16:21
  • I kinda figured out a way I don know if its good practice or not. – Hemen Jun 21 '16 at 17:08
  • @rrauenza `mi = msignup.objects.get(pk=userID) form = accountSettingsForm(instance=mi)` – Hemen Jun 22 '16 at 11:25
  • Doesn't that setup the form for updating that object's instance? – rrauenza Jun 22 '16 at 15:00
  • exactly I want to update that certain instance of the object! is it good practice? Maybe I worry too much about good practice! – Hemen Jun 23 '16 at 19:04

0 Answers0