1

When I extend the Django User using a OneToOneField to create a Manager, the form to create a Manager in Django Admin only has fields for username and password.

class Manager(models.Model):
    """
    Users who need to login to manage the listing of a Outlet
    are represented by this model.
    """
    manager = models.OneToOneField(User)
    internal_notes = models.TextField(blank=True)

    def __unicode__(self):
        return self.manager.username

What is the right way to add the other built-in User fields like first_name etc to my Manager model?

Pranab
  • 2,207
  • 5
  • 30
  • 50
  • Look at this answer here, it explains the best way to customize and extend User. http://stackoverflow.com/questions/19433630/how-to-use-user-as-foreign-key-in-django-1-5/19434182#19434182 – Chris Hawkes Jun 29 '15 at 13:00
  • such fields are provided by Django's User class already. Also the type of User is an attribute already, if I am not mistaken, so you might want to use that. In case, simply add the fields you require to your class (i.e. Manager) – Pynchia Jun 29 '15 at 13:01

1 Answers1

0

It's not clear what you are asking here. The form to create a User (not a Manager) displays only three fields at first, to allow you to set the password, but then continues on to a second form where you can set other fields including first name.

Your Manager class doesn't need to define those fields, since they are attributes of the User class which you access via the one-to-one relation.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • I see. I was expecting the form to create a Manager would display all the fields that Manager contained - which would include all those that User contained; in fact I am still puzzled why it displays only those 3 fields. – Pranab Jun 29 '15 at 18:01
  • I don't understand what three fields you mean, actually. Your Manager form does only display the fields that Manager contains - the user (which you've called `manager`, for some reason) and `internal_notes`. All the other fields are on User itself. And the initial form for creating a user only displays username and password, it doesn't even show email at that stage. – Daniel Roseman Jun 29 '15 at 18:08
  • Actually I have to unregister User first for it to work right. Why? admin.site.unregister(User) admin.site.register(User) – Pranab Jun 29 '15 at 22:56