我开始向django网站添加用户用户身份验证。并按User
添加OneToOneField
字段的班级人员。我转到http: //localhost:8000/admin
页面并尝试添加学生
但学生只有Born, Record book, User(which have only Имя пользователя, Пароль)
。但没有email, first_name, lastname
。为什么呢?
models.py:
class People(models.Model):
user = models.OneToOneField(User)
born = models.DateField() # born date
class Meta:
abstract = True
class Student(People): # Ingeritance
record_book = models.CharField(max_length=75) # students record book
group = models.ForeignKey(Group)
def __unicode__(self):
return "Student:" + self.user.name + ' ' + self.user.surname
def get_absolute_url(self):
return "/student/%i/" % self.id
我看到此rus django book和此tango with django
admin.py:
# -*- coding: utf-8 -*-
from django.contrib import admin
from models import Professor, Student, Subject, Group, PageLaboratoryWork, MadeLaboratoryWork, LabComment
admin.site.register(Professor)
admin.site.register(Student)
admin.site.register(Subject)
admin.site.register(Group)
admin.site.register(PageLaboratoryWork)
admin.site.register(MadeLaboratoryWork)
admin.site.register(LabComment)
答案 0 :(得分:1)
像这样更改admin.py
:
class UserInline(admin.StackedInline):
model = User
extra = 1
class PeopleAdmin(admin.ModelAdmin):
inlines = [UserInline]
admin.site.register(People, PeopleAdmin)
答案 1 :(得分:1)
from models import Student
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
admin.site.register(Student)
admin.site.unregister(User)
class MyUserAdmin(UserAdmin):
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('username', 'email', 'first_name', 'last_name', 'password1', 'password2')}
),
)
admin.site.register(User, MyUserAdmin)