arcee123
arcee123

Reputation: 211

User Model fields not showing in Django Admin Panel

I have a basic model that extends the User model:

from django.contrib.auth.models import User

class Promotion (models.Model):
    User = models.ForeignKey(User)
    Rating = models.ForeignKey(Rating)
    Date_Effective = models.DateField()

    def __str__(self):
        return self.Rating.Rank.Short_Rank + ' ' + self.User.last_name + ' (' + str(self.Date_Effective) + ')'

in my Admin.py, i have the models showing:

admin.site.register(models.Promotion)

when loading a promotion, the Short_Rank field and the Date_Effective fields show perfectly, but the User.last_name does not.

ADM (2017-03-18)

enter image description here

This is consistent with the rest of the models, and I am believing that the User model itself is not being attacked by the query in the admin panel. How do I get the name fields in the User model showing in the model page of the Admin panel? Thanks.

Upvotes: 1

Views: 1085

Answers (1)

Gagik Sukiasyan
Gagik Sukiasyan

Reputation: 856

You need to have one to one relation when you want to extend the auth user. Please refer to this discussion .

Here is how you can change it and I expect it should work for you:

class Promotion (models.Model):
   User = models.OneToOneField(User)
   Rating = models.ForeignKey(Rating)
   Date_Effective = models.DateField()

Upvotes: 1

Related Questions