Reputation: 425
I'm trying to create an app where a person can login, do stuff, and see their personal information like their first_name, last_name, email, username, etc. So far I have the application displaying their username and email, but not first_name or last_name.
If I go on the admin site and I look under "Users", it only displays the username and email of the user, but not the first_name or last_name. So that's most likely the problem, but I don't know how to get this information to "save."
Here's my "Student" model:
class Student(models.Model):
user = models.OneToOneField(User)
first_name = models.CharField(max_length=200, null=True)
last_name = models.CharField(max_length=200, null=True)
email = models.CharField(max_length=200, null=True)
EDIT: I created a student admin with all that information. Here's what it looks like:
class StudentAdmin(admin.ModelAdmin):
list_display = ('username', 'email', 'first_name', 'last_name')
inlines = StudentInline
If I manually add the first and last name of the user, it works perfectly. But it's not adding them even after this change.
Upvotes: 2
Views: 1431
Reputation:
I recommend looking into the Admin Site section for this and the section known as list_display. https://docs.djangoproject.com/en/1.9/ref/contrib/admin/
How I done this in a recent app was the list_display section to display only area of the app I wanted to see in the dropdown.
@admin.register(Surah)
class SurahAdmin(admin.ModelAdmin):
# Note: Admin Interface to maintain Surah Information
list_display = [ '__str__', 'lk' ] # Show the List of every Surah
list_filter = [ 'nm' ] # The Side box for filters
search_fields = [ 'nm' ] # A Search field
ordering = [ 'id' ] # How you want to order it
# Note: Additional Inline Information
inlines = [ AyahsInline ] # Look to inline, mainly for One
# to many relationship
Upvotes: 1
Reputation: 6120
If you need to show the Student model, You need to add them to your list_display in the admin.py file to show the screen like this.
But it seems like you are clicking on the User in the admin and not the student.
Upvotes: 0