I have three models: Person, Client, Member
Person is a base model, Client and Member are profiles for Person.

class Person(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(
        verbose_name=_('email address'),
        max_length=255,
        unique=True,
    )


class Client(User): #or maybe models.Model and explicit OneToField 
    first_name = models.CharField(verbose_name=_('first name'), 
max_length=30)
    last_name = models.CharField(verbose_name=_('last name'), max_length=30)

class Member(User): #or maybe models.Model and explicit OneToField 
    description = models.CharField(verbose_name=_('first name'), 
max_length=255)
   # other stuff


So, what I want?
1. In admin, when we add client or member, I want to fill field email 
(fields from base class) as if it was in derived class. For example, in 
admin list_display = ('email', 'first_name'). Not select boxes for user.
2. Person class can be instantiated separately and the "attached" to the 
created profiel. Like person=Person(email="t...@gmail.com"), client = 
Client(person=person,first_name="test"...). Especially, this should work in 
forms. When user (person) is authenticated I want to give ability to fill 
in profile (client) form and attach person to this form.
3. One person can have both accounts. If I delete client/member, 
corresponding person should not be deleted.

3rd option actually is not necessary, but it is useful for me to know how 
to do it.

So, option 1 is perfectly solved by inheritance, Person is User, but this 
approach fails when option 2 is implemented. Since Person and Client is 
considered as one whole, I can't attach user, duplicate key error.
Option 2 is resolved by extending models.Model and appending 
person=models.OnetoOneField(Person,primary_key=True). However, admin is 
broken (1st option), because Client don't have fields like email.


So, what approach to take in order to solve above issues?
Are there simple ways?
If there are no simple ways, is there advanced way, like overriding 
metaclass, object descriptors or writing custom OneToOne field?

Any suggestions are welcomed.

Thank you. 

-- 
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+unsubscr...@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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/280bb9b1-f667-423d-81e3-4ea6e0c84c59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to