Hi,

Django doesn't really provide a way to create a subclass from an already 
existing object in the admin. It's actually pretty hard to do even in the 
code. So for that reason I'd recommend the non subclass with the 
OneToOneField.

Actually, if I were doing it, this is what I would do:

class User(AbstractBaseUser):
    is_client = models.BooleanField(default=False)
    is_member = models.BooleanField(default=False)
    description = models.CharField(verbose_name=_('first name'), max_length=
255, blank=True)
    # include both client and member fields here and have them be blank=True

Collin

On Tuesday, January 20, 2015 at 7:52:38 AM UTC-5, Paul Royik wrote:
>
> 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="te...@gmail.com <javascript:>"), 
> 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/d8ca1b3c-59fe-434a-bbe7-e916d0312e9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to