I don't think there will be any problem with what you are doing.
You can define the unicode function to return the username of doctor or frontdesk user in this way:
def __unicode__(self):
return self.user.username
سؤال
I have an application where the amount of users logging in to system will be not more than 10 or 15. I have two type of users - a frontdesk user and a doctor type. Both of them have some common fields and some unique ones. For e.g a doctor might have a field like cardio or pediatrician, etc. The django recommended way of extending user model, does authenticate one type of users only I think. Would making a Doctor model with a OneToOneField be an accepted way to implement this?
class Doctor(models.Model):
#doctor specific fields
user = models.OneToOneField(User)
class FrontDesk(models.Model):
#frontdesk specific fields
user = models.OneToOneField(User)
And for frontdesk the same way?
I am using django 1.5. Django user model also uses username for returning value in the __unicode__
function. I want the user to be able to see the name of the doctor. So the built-in functionality isn't OK for me. What would you suggest?
المحلول 2
I don't think there will be any problem with what you are doing.
You can define the unicode function to return the username of doctor or frontdesk user in this way:
def __unicode__(self):
return self.user.username
نصائح أخرى
why not combine them with abstract:
class CommonCustomer(models.Model):
user = models.OneToOneField(User)
#all common fields
class Meta:
abstract = True
class Doctor(CommonCustomer):
#doctor specific fields
docid = models.CharField(max_length=32)
class FrontDesk(CommonCustomer):
#frontdesk specific fields
fdid = models.CharField(max_length=32)