I have model:
class Lecturer(User):
title = models.CharField(max_length=20)
URL = models.URLField(null=True, blank=True)
objects = UserManager()
def about(self):
return u"%s %s %s" % (self.title, self.first_name, self.last_name)
def __unicode__(self):
return u"%d %s %s %s" % (self.pk, self.first_name, self.last_name, self.title)
class Meta:
db_table = 'lecturer'
Now, I want to make new Lecturer, but using already existing User. Unfortunately this is not working:
>>> u = User.objects.get(pk=2)
>>> u
<User: nick>
>>> new = Lecturer(user_ptr_id=2, title='title', URL='url.com')
>>> new.username
u''
I've tried using User object instead of id, 'pk' instead of 'user_ptr_id', nothing... Any ideas?
It's not such a good idea to extend from django.contrib.auth.User
You can set custom authentication requirements by using AUTH_USER_MODEL
Otherwise it might be easier to just create a One to One relationship between you Lecturer and django's User. This is also described in the django documentation.
The overall idea is that the django.contrib.auth.User
class' responsibility is to provide authentication functionality. It's not meant to be extended with business functionality. If you need that kind of functionality then it's probably better to create another hierarchy of classes that have a one to one reference to django.contrib.auth.User