2013年9月27日金曜日 10時03分09秒 UTC+9 Yu Chen:
In the sample code, CBV has to attached to FormView and has to provide one 'form_class' member. Another extra form is set by context_data. It is still not perfect. For example, consider a dynamic formset with which you can create new objects by adding new forms in UI. In this case, it is not easy to handle all forms in one view.
/Adam
-- Inlineformset may solve your problem, and this http://haineault.com/blog/155/ is a good example.
In the sample code, CBV has to attached to FormView and has to provide one 'form_class' member. Another extra form is set by context_data. It is still not perfect. For example, consider a dynamic formset with which you can create new objects by adding new forms in UI. In this case, it is not easy to handle all forms in one view.
/Adam
在 2013年9月26日星期四UTC+8下午1时19分41秒,Adam写道: Hi,
I am trying to handle 2 ModelForm in 1 view. Is that possible with CBV solution? Does any best practise exist?
Here is the problem in details.
## models.py
class UserProfile(HasJPAddresses, models.Model):
user = models.OneToOneField(User)
birthdate = models.DateField(default='1900-01-01')
## forms.py
class UserProfileUpdateForm(forms.ModelForm):
class Meta:
model = UserProfile
class UserUpdateForm(forms.ModelForm):
class Meta:
model = User
fields = ['first_name', 'last_name']
## views.py
class UserProfileUpdateView(FormView): <<<<<<<---- How could I handle two forms at once in a view?
Thanks,
/Adam
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment