我有一个字段,我必须在Meta类中编写函数,在我的字段字段中对我的日期进行排序。请帮帮我
from django.db import models
class Aaa(models.Model):
fields = models.IntegerField()
class Meta:
app_label = 'project'
答案 0 :(得分:3)
我建议您仔细阅读文档,特别是:https://docs.djangoproject.com/en/dev/ref/models/options/#django.db.models.Options.ordering
class Tag(models.Model):
test_case_counter = models.IntegerField(default=0)
my_date_field = models.DateField(auto_now=True,auto_add=True)
class Meta: # notice indentation
ordering = ['my_date_field']
app_label = 'project'