I have expanded auth.User (gosh that seems to be a popular thing to do) according to the instructions here: http://code.djangoproject.com/wiki/ExtendedUserModel The particulars are more complicated to explain than the code itself:
class User(users.User): id = meta.OneToOneField(Node, db_column='id') class META: replaces_module = 'auth.users' module_name = 'users' The first question you're probably asking (beyond "What the hell are you thinking?") is "What's Node?" The short answer is: class Node(meta.Model): title = meta.CharField(maxlength=255, blank=False) nodetype = meta.CharField(maxlength=30) def __repr__(self): return self.title I also have a Document model that is likewise very simple: class Document(meta.Model): node = meta.OneToOneField(Node) content = meta.TextField() Every Document is-a Node. Every User is-a Node. Assume I have various other kinds of things that are also Nodes. If I want the User to also have a Document tied to its Node (say, for a bio or whatnot), that is quite simple to arrange. This is all fine and dandy, but changing the id field like this isn't doing precisely what I want: The normal, default, AutoField id field is named 'id', i.e.: >>> from django.models.node import nodes >>> n = nodes.get_object(pk=3) >>> n.id 3 But with my User model: >>> from django.models.auth import users >>> u = users.get_object(pk=3) >>> u.id Traceback (most recent call last): File "<console>", line 1, in ? AttributeError: 'User' object has no attribute 'id' >>> u.id_id 3 Duh! The magic turns id into id_id. It's just what OneToOneField does. This difference in the interfaces of my User class and the standard one rears its ugly head when I try to log in to the admin: [snip] Exception Value: 'User' object has no attribute 'id' [snip] /usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/contrib/admin/views/decorators.py in _checklogin 85. request.session[users.SESSION_KEY] = user.id [snip] Oh dear. I have two options as I see it: I can either edit the admin code (not preferable for any number of reasons), or I can somehow convince an id attribute to spring into existance. Being relatively new to Django, I am not sure of the best way to do either of these. -Kirk McDonald PS: The following hackish thing occurs to me: class User(users.User): node = meta.OneToOneField(Node, db_column='id') id = meta.IntegerField(db_column='id', editable=False) class META: replaces_module = 'auth.users' module_name = 'users' Is this a completely terrible idea? I haven't tested it yet, though instinct tells me I'll almost certainly have to set the db table up myself... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---