0

I am new to programming Django, so I'm not sure if this is possible.

I have created a new CustomUser class:

class CustomUser(AbstractBaseUser):
    email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
    mobile = models.CharField(max_length=30, null=True)
    first_name = models.CharField(max_length=50, null=True)
    middle_name = models.CharField(max_length=50, null=True)
    last_name = models.CharField(max_length=50, null=True)
    date_of_birth = models.DateField(null=True)
    Primary_address = models.CharField(max_length=50, null=True)
    Primary_address_zipcode = models.CharField(max_length=5, null=True)
    is_active = models.BooleanField(default=False)
    is_admin = models.BooleanField(default=False)
    date_joined = models.DateTimeField(default=timezone.now)

A few questions:

Question 1: I have redefine some of the fields that exists in the default User class (e.g. First Name, Last name, Date Joined). However, I didn't define Last_login. But last_login still shows up as a column in the admin page. But if I don't define First Name, Last Name and Date Joined in my new CustomUser, I get an error and doesn't show up in the admin page. Why is last login special?

Question 2: The default admin page has great UI for group and permission control. Is it possible to define my CustomerUser and still use/enable the default admin page?

enter image description here

Thanks.

Louis Barranqueiro
  • 10,058
  • 6
  • 42
  • 52
H C
  • 1,138
  • 4
  • 21
  • 39
  • Possible duplicate of [Django custom user model: How to manage staff permissions?](http://stackoverflow.com/questions/17365876/django-custom-user-model-how-to-manage-staff-permissions) – Jared Mackey Nov 14 '15 at 17:01
  • I think I'm asking a slightly different question about the Django admin UI. – H C Nov 14 '15 at 18:11
  • One question per question please – Foon Nov 14 '15 at 23:00

1 Answers1

0
  1. you dont need to define all these fields that are already there in django. dont reinvent the wheel. what error are you getting? traceback?

  2. using your customuser model has nothing to do with using default admin page. you can always use django admin page no matter what models you have. Or i dont understand what you really want to achieve.

doniyor
  • 36,596
  • 57
  • 175
  • 260
  • 1. when I comment out first name. I don't have this problem with last_login eventhough I never defined it: I get the following problems with list_display: ERRORS:The value of 'list_display[1]' refers to 'first_name', which is not a callable, an attribute of 'CustomUserAdmin', or an attribute or method on 'sites.CustomUser'. – H C Nov 14 '15 at 21:53
  • @doniyr 2. When I use the default UserAdmin, all the Group control disappears. – H C Nov 14 '15 at 21:57