0

Let's say I have an app that has 3 kinds of user

  • Employee with fields like work_number, department etc.
  • Member with fields like phone_number, .....
  • Agent with fields like company_name,.....

They're different.

I write models like this:

class Employee(models.Model): user = models.OneToOneField(User) department = models.CharField(max_length=100) ....... class Member(models.Model): user = models.OneToOneField(User) ....... class Agent(models.Model): user = models.OneToOneField(User) ....... 

Now I can :

u = User.objects.get(username='xxxx') u.employee // it works... 

but, ONE user has THREE profiles (employee,member,agent) !!!

It's not matches my business, the business role is ONE user could be and must be only one kind of 3 profiles.

What's the best way to solve this?

2
  • So you're saying you want a User to only be one of three profiles? How are the profiles created? Commented May 19, 2015 at 11:47
  • The registration form creates one user and the profile Commented May 19, 2015 at 16:15

1 Answer 1

1

Why not have a single profile with a role associated (even if certain fields will never be filled for a specific role)?

You can handle the validation through forms and instead having 3 different models you would have 3 different forms.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the best solution because you can than just go to user.profile instead of user.employee, user.member etc.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.