On Oct 30, 8:11 pm, Alex G <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've been trying for some time to create a polymorphic link with a
> backwards-link from the associated model.  The problem is the model is
> django.contrib.auth.models.User...  Is there any way to add this
> functionality without changing the django core?  Trying to call
> setattr(django.contrib.auth.models.User, 'target',
> generic.GenericRelation(MyUser) does not work.  It instantiates an
> attribute named 'target', but it doesn't work in the manner
> intended...
>
> from django.contrib.auth.models import User as Account
> from django.contrib.contenttypes.models import ContentType
> from django.contrib.contenttypes import generic
> class User(models.Model):
>         account_polymorphic_link = models.ForeignKey(ContentType)
>         account_id = models.PositiveIntegerField()
>         account = generic.GenericForeignKey('account_polymorphic_link',
> 'account_id')
>
> setattr(Account, 'target', generic.GenericRelation(User)) #this
> doesn't seem to work
>
> My problem is that I'm using auth.User (Account in the above example)
> to store username/password and to leverage permissions and such, but I
> can't look someone up by username and get at the information in my
> derivative class...
>
> Does anyone have any ideas/suggestions?
>
> Thank you,
>
> Alex.

Well, you can use generic relations without the backwards link, by
simply looking up the content_type/object_id in the related class.

But for your use case, a much better way is to use the built-in
AUTH_PROFILE_MODULE setting, which allows you to nominate a class
which extends User, and enables a user.get_profile() method. See
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

--
DR.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to