[Python-il] [pyweb-il:385] Re: a question re pluggable apps
Idan Gazit
idan at pixane.com
Tue Sep 1 12:49:26 IDT 2009
Ofri,
There's an officially-sanctioned way to do it which is not far from
what you suggest. It's in the docs, too:
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
The short of it is have one model which stores the "extended user
profile data", with:
user = models.ForeignKey(User, unique=True)
And then in settings.py have AUTH_PROFILE_MODULE =
'myapp.mymodule.MySuperProfileModel'
If you have any user object, you can do user.get_profile() and it will
return the related instance of your extended profile model.
There's also an older post by James Bennett on the subject, but it
predates this "official" way so don't get confused.
-I
On Sep 1, 2009, at 12:23 PM, ofri raviv wrote:
> Hi,
>
> I have a question about pluggable apps design: many times, you'd
> like a new app to add some fields to the basic models you already
> have. for example, if I have a users app, and i want to add karma
> (everything good you do on the site gives you good karma points,
> when you post, when your posts are voted up, etc). it doesn't really
> matter how the karma app works, in the end, it has to add a karma
> field to the user model that is already defined in another app.
>
> the solution seems to be, add another model, UserKarma, that has
> user = models.OneToOneField(User, primary_key=True,
> related_name='karma')
>
> and then we can use user.karma.foo to access the fields that karma
> app added.
>
> is that a good solution? how is it performance-wise compared to just
> adding the fields to User?
>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google
> Groups "PyWeb-IL" group.
> To post to this group, send email to pyweb-il at googlegroups.com
> To unsubscribe from this group, send email to pyweb-il+unsubscribe at googlegroups.com
> For more options, visit this group at http://groups.google.com/group/pyweb-il?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2413 bytes
Desc: not available
Url : http://hamakor.org.il/pipermail/python-il/attachments/20090901/cb23b212/attachment.bin
More information about the Python-il
mailing list