我正在为我的 Django 博客应用程序制作模型。但是在运行 python manage.py makemigrations blog
时,我收到此错误消息:
SystemCheckError: System check identified some issues:
ERRORS:
blog.Post: (models.E014) 'ordering' must be a tuple or list (even if you want to order by only one field).
这是我的 models.py
文件:
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
class Post(models.Model):
STATUS_CHOICES = (
('draft','Draft'),
('published','Published')
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250,unique_for_date='publish')
author = models.ForeignKey(User,on_delete=models.CASCADE,related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10,choices=STATUS_CHOICES,default='draft')
class Meta:
ordering = ('-publish')
def __str__(self):
return self.title
错误说我的顺序应该是列表或元组。但它已经是。 我无法理解这个错误。有人可以帮帮我吗?提前致谢
最佳答案
试试这个:
ordering = ('-publish',)
关于python - blog.Post : (models. E014) 'ordering' 必须是元组或列表(即使您只想按一个字段排序)。在 Django ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64606330/