到目前为止,这是我的models.py页面:
from django.db import models
from datetime import date
from django.conf import settings
class Star(models.Model):
thumbnail = models.TextField()
title = models.CharField(max_length = 200)
description = models.TextField()
star_power = models.TextField()
def __str__(self):
return self.title
class recent_update(models.Model):
title = models.CharField(max_length = 200)
description = models.TextField()
video = models.TextField()
date = models.DateField(("Date"), default=date.today)
ordered_videos = recent_update.objects.order_by('-created_date')
def __str__(self):
return self.title
但是我的终端机说未定义last_updates。我需要组织模型内容,以便创建的最新模型位于页面顶部。最旧的模型位于页面底部。
答案 0 :(得分:0)
正确的方法是创建额外的字段名称:
class RecentUpdate(models.Model):
title = models.CharField(max_length = 200)
description = models.TextField()
video = models.TextField()
created = models.DateTimeField(auto_now_add = True, auto_now = False)
def __str__(self):
return self.title
class Meta:
ordering = ('-created')
以上创建字段仅在创建表实例期间首次添加。