Manan Mehta Manan Mehta - 1 month ago 17
Python Question

Django extending model.User

I am trying to extend model.User in Django (using SQLite3). Here's my Model for UserProfiles:

class UserProfile(models.Model):
user = models.ForeignKey(User, unique = True, related_name = 'user')
bio = models.TextField(blank = True, null = True)
birth_date = models.DateField(blank = True, null = True)
followers = models.ManyToManyField('self', symmetrical=False, null = True, blank = True)


But when I run the server, I don't see UserProfiles as a separate tab. There exists a User tab but I don't see any of my custom fields in there. Am I doing something wrong or is this the expected behavior of Django? And how can I test this much code (manually is fine but how?) just to see if the behaviour is as expected.

Thank you very much!

Answer

Okey, you need to add UserProfile model to your admin panel.

Inside app folder where UserProfile is located, you will find a file named admin.py

Add the following:

from .models import UserProfile

admin.site.register(UserProfile)
Comments