Django: How to initiate/gather field data from two models in one form definition -


I am using a model for user to edit firstform and last_name, but I want to add additional fields from UserProfile Should 1-to-1 relationship with user) added in this.

UserProfileInfoForm (forms.ModelForm): "Profile Model Field Specification for Editing" "" Category Meta: Model = User Field = ('First_name', 'Last_Name', 'User_PhoneMobile '' (Label = _ ('first name'), max_text = 30, required = true) last_name = forms.charfield (label = _ ('last name'), max_length = 30, required = true) user_phonemobile = forms. CharField (label = _ ('mobile phone'), max_length = 15, required = false)

I have additional fields in the modelform (and on the page ), But I can not afford it with value from other mo Dell (Userprofile)

I can make it a normal form and can populate it in my view like this

>

  userdata = request.user.get_profile () data = {'first_name': request.user.first_name, 'last_name': request.user.last_name, 'User_phonemobile': userdata.user_phonemobile,} ProfileIfoform = UserProfileInfoForm (Data)  

But in the future, when adding additional fields it seems like this is my view Definition will clutter.

Regards,

Gerrard.

I usually create just two variations, see an example for each model, an example for.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -