On Thu, 2009-02-19 at 14:53 -0800, Gok Mop wrote: > I'm struggling with how to design something, and I'm pretty sure > somebody has an easy solution. > > I need to store different information about different classes of > users. I want to attach those classes as the user profile to my > django.contrib.auth.User object, so I can always cross-walk from the > User object to my profile object, and vice versa. The trouble is that > I have more than 1 profile object. > > My multiple profile objects share a common superclass: > > class MyPerson(models.Model): > user = models.ForeignKey(User, unique=True) > (...handful of other things...) > > (In settings, I specify AUTH_PROFILE_MODULE="myapp.myperson") > > I then have 4-5 objects that extend MyPerson and tack on all the stuff > specific to that object. > > When I create users and associate profiles, that works great. When I > 'restore' a user from the database and ask for the profile, I get a > MyPerson object, and I've lost the linkage to my subclass...and I'm up > a river.
You get back the MyPerson object because that's the model you've specified as the profile class. Django's model inheritance does *not* automatically descend to the most derived child class instance. There are a number of good reasons for that, all covered in other threads on both this list and django-developers. You can still descend to the child classes, since they're linked via one-to-one fields, so it's a reverse relation access. Or you could include a type field in the MyPerson model that indicates the type of the child model, so that you know immediately which type of model it is. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---