Hi all!
What would be the best way to extend User class?
subclassing makes another table and wiki ->
http://www.djangoproject.com/documentation/models/subclassing/
different from m-r.
remove_fileds dosen't work and in admin it is possible to add info to
new class but not to modify it:
from django.contrib.auth.models import User
class myuser(User):
homeaddress=models.CharField(maxlength=10)
def __repr__(self):
return self.username
module_name='myusers'
class Admin:
pass
give error in admin when you click on that myuser:
AttributeError at /admin/shop/myuser/1/
'User' object has no attribute 'homeaddress'
After playing with OneToOne and foreign fileds got this:
----
class Myuser(models.Model):
user = models.ForeignKey(User, blank = True,null=True, default =
None, edit_inline=models.TABULAR)
name = models.CharField(maxlength=10,core=True)
gender=models.CharField(maxlength=10,core=True)
address=models.CharField(maxlength=10,core=True)
def __repr__(self):
return self.name
def save(self):
if not self.user_id:
u=User(username=self.name)
u.save()
self.user_id=u.id
super(Myuser, self).save()
class Admin:
ordering = ['?']
-----
This way it is create a user in auth_user table and add extra info to
myuser table.
so it would be possible to get user.id from auth_user table.
Is it any better way?
And there are any documentation about subclassing for m-r?
And cannot find documentation about extending admin without patching
django source.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---