简体   繁体   中英

Model doesn’t show in admin

I am currently working on a science django blog. I've finished coding it all and I realized that the models items overview and content don't appear in my django.admin. Here's an image so you can see. 在此处输入图像描述

I know there are other threads related to it. However, I couldn't find the solution in those.

Models.py:

class Post(models.Model):
    title = models.CharField(max_length=100)
    overview = models.TextField()
    timestamp = models.DateTimeField(auto_now_add=True)
    content = HTMLField()
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    thumbnail = models.ImageField()
    categories = models.ManyToManyField(Category)
    featured = models.BooleanField()
    previous_post = models.ForeignKey(
        'self', related_name='previous', on_delete=models.SET_NULL, blank=True, null=True)
    next_post = models.ForeignKey(
        'self', related_name='next', on_delete=models.SET_NULL, blank=True, null=True)

Admin.py:

from django.contrib import admin
from .models import Author, Category, Post, Comment, PostView
# Register your models here.
admin.site.register(Author)
admin.site.register(Category)
admin.site.register(Post)

Settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    'crispy_forms',
    'tinymce',

    'marketing',
    'posts'
]

And urls.py:

urlpatterns = [
    path('admin/', admin.site.urls),

By the way, the models.py is in the app Posts. Just in case somebody needs this information.

The other models work perfectly. It's just the overview and the content

Use this:-

content = models.TextField()

Instead of:-

content = HTMLField()

AND then make migrations, migrate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM