Hi,

I realized a new way to extend user models, it is simpler than official
get_profile approach of django[1] as there is only one model to work with,
and relationships are kept on the right model, and gives a less hacky feel
than "replaces_module" method[2].

User.add_to_class("openid", models.URLField(blank=True))
User._meta.admin.fields += (
    ("AmitCom Extensions", { 'fields': ('openid', ) }),
)

*class* UserExtension(object):
    *def* _get_comments(self):
        *return* Comment.objects.get(user=self, is_public=True)
    public_comments = property(_get_comments)
    *del* _get_comments

User.__bases__ = User.__bases__ + ( UserExtension, )

Read my blog post about the same[3] for a longer discussion about pros and
cons. How does it sound?

1. http://www.b-list.org/weblog/2006/06/06/django-tips-extending-user-model
2. http://code.djangoproject.com/wiki/ExtendedUserModel
3. http://www.amitu.com/blog/2007/july/django-extending-user-model/

-- 
Amit Upadhyay
http://www.amitu.com/blog/
+91-9820-295-512

--~--~---------~--~----~------------~-------~--~----~
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