Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:51:42+00:00 2026-05-31T15:51:42+00:00

Initially, I started my UserProfile like this: from django.db import models from django.contrib.auth.models import

  • 0

Initially, I started my UserProfile like this:

from django.db import models
from django.contrib.auth.models import User

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    verified = models.BooleanField()
    mobile = models.CharField(max_length=32)

    def __unicode__(self):
        return self.user.email

Which works nicely along with AUTH_PROFILE_MODULE = 'accounts.UserProfile' set in settings.py.

However, I have two different kinds of users in my website, Individuals and Corporate, each having their own unique attributes. For instance, I would want my Individual users to have a single user only, hence having user = models.OneToOneField(User), and for Corporate I would want them to have multiple users related to the same profile, so I would have user = models.ForeignKey(User) instead.

So I thought about segregating the model into two different models, IndivProfile and CorpProfile, both inheriting from UserProfile while moving the model-specific attributes into the relevant sub-models. Seems like a good idea to me and would probably work, however I would not be able to specify AUTH_PROFILE_MODULE this way since I’m having two user profiles that would be different for different users.

I also thought about doing it the other way around, having UserProfile inherit from multiple classes (models), something like this:

class UserProfile(IndivProfile, CorpProfile):
    # some field

    def __unicode__(self):
        return self.user.email

This way I would set AUTH_PROFILE_MODULE = 'accounts.UserProfile' and solve its problem. But that doesn’t look like it’s going to work, since inheritance in python works from left to right and all the variables in IndivProfile will be dominant.

Sure I can always have one single model with IndivProfile and CorpProfile variables all mixed in together and then I would use the required ones where necessary. But that is just doesn’t look clean to me, I would rather have them segregated and use the appropriate model in the appropriate place.

Any suggestions of a clean way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:51:44+00:00Added an answer on May 31, 2026 at 3:51 pm

    I have done it this way.

    PROFILE_TYPES = (
        (u'INDV', 'Individual'),
        (u'CORP', 'Corporate'),
    )
    
    # used just to define the relation between User and Profile
    class UserProfile(models.Model):
        user = models.ForeignKey(User)
        profile = models.ForeignKey('Profile')
        type = models.CharField(choices=PROFILE_TYPES, max_length=16)
    
    # common fields reside here
    class Profile(models.Model):
        verified = models.BooleanField(default=False)
    

    I ended up using an intermediate table to reflect the relation between two abstract models, User which is already defined in Django, and my Profile model. In case of having attributes that are not common, I will create a new model and relate it to Profile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started an app that was initially a testing platform--user management, and managers that
Initially I thought this was going to work, but now I understand it won't
Initially my app's bundle identifier was the default MyCompany.${PRODUCT_NAME:rfc1034identifier} This wasn't matching the app
I initially asked this on Superuser, but somebody advised me to repost here. I
I have started initially with VC++ 2008 Express. I've noticed that GCC becomes kind
I started down this path of implementing a simple search in an array for
I'm getting started with Flex and initially installed the Adobe environment ( Flex Builder
I have started playing around with Berkeley DB. This one is really interesting, but
Our team is developing a rather big ASP.NET web project which initially started in
I am an experienced Mac/iOS developer, but I initially started to program in C++.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.