all fields of a model cannot be displayed in the background of django, and new records of the model cannot be manually added in the background. Check the database with shell and find that the data exists and the application runs normally. Other models can be displayed normally, I don"t know why. Django version is 1.11
models.py
from django.db import models
class User(models.Model):
openid = models.CharField(max_length=20)
nickname = models.CharField(max_length=20,null=True)
def __str__(self):
return self.nickname
class Record(models.Model):
expression = models.CharField(max_length=100)
user = models.ForeignKey(User)
time = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.expression
admin.py
from django.contrib import admin
from .models import User,Record
class RecordAdmin(admin.ModelAdmin):
list_display = ("expression","user","time")
class UserAdmin(admin.ModelAdmin):
empty_value_display = ""
list_display = ("openid","nickname")
admin.site.register(User,UserAdmin)
admin.site.register(Record,RecordAdmin)