This is actually a follow-up to a previous question.
A user's profile data is spread over several different models, like so:
# Simplified versions, actual classes contain many more fields.
class Profile(models.Model): # returned by Django's User.get_profile()
user = models.OneToOneField(User)
home_address = models.OneToOneField(Address)
work_address = models.OneToOneField(Address)
language = models.CharField(max_length=20)
class Address(models.Model):
street = models.CharField(max_length=100)
city = models.CharField(max_length=100)
... and Django's User
, of course.
I want the user to enter all of his profile data in one view, in particular these pieces of information:
- username (User)
- email (User)
- language (Profile)
- home_address.street (Address)
- home_address.city (Address)
- work_address.street (Address)
- work_address.city (Address)
So, what would be the simplest/Django way to
- construct such a form?
- output the form in the template?
- handle the incoming form data, split it to different models and create the necessary objects (i.e. a
User
, aProfile
and 2Address
objects)?