You should study the officially recommended way to expand the User model first, as can be seen from the documentation , which, in my opinion, comes directly from the project managerβs personal blog about the subject . (The actual blog article is quite old, now)
As for your actual problem with forms, look at the project manager, who can reuse the django-profiles application, and see if your code fixes your problem. In particular, these functions and the types in which they are used.
Edited to add:
I looked into it a little (since I needed to do it myself). Something like this seems to be enough:
# apps.profiles.models from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) ... birth_date = models.DateField(blank=True, null=True) joined = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) class Meta: verbose_name = 'user profile' verbose_name_plural = 'user profiles' db_table = 'user_profiles' class Address(models.Model): user = models.ForeignKey(UserProfile) ...
I used "..." to edit the content in the code above. I have not tested this yet, but, looking at the examples and documentation on the forms, I believe that this is correct.
Note. I put the FK from the Address model in UserProfile, and not vice versa, as in your question. I believe inline forms require this to work correctly.
Then, of course, in your views and templates you will process UserForm, UserProfileForm, and AddressFormSet separately, but they can all be inserted into the same form.
jonwd7
source share