gpt4 book ai didi

python - 错误 : blog. Post : (models. E015) 'ordering' 指的是不存在的字段、相关字段或查找 'publish' 。我该如何解决?

转载 作者:行者123 更新时间:2023-12-05 06:08:32 25 4
gpt4 key购买 nike

每当我尝试迁移我的模型时。我不断收到此错误:

ERRORS:blog.Post: (models.E015) 'ordering' refers to the nonexistent field, related field, or lookup 'publish'.

这是我的模型文件。

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User


# Create your models here.


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()
published = 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

导致错误的行。

    class Meta:
ordering = ('-publish',)

我想要一个快速的解决方案。提前致谢

最佳答案

是不是错别字问题?模型中字段的名称是 published 但在元中是 publish

尝试将您的元更改为:

class Meta:
ordering = ('-published',)

关于python - 错误 : blog. Post : (models. E015) 'ordering' 指的是不存在的字段、相关字段或查找 'publish' 。我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65118618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com