0
我有一個字段,我必須在Meta類中編寫函數,該函數在我的字段字段中排序了我的日期。請幫我如何編寫排序功能
from django.db import models
class Aaa(models.Model):
fields = models.IntegerField()
class Meta:
app_label = 'project'
我有一個字段,我必須在Meta類中編寫函數,該函數在我的字段字段中排序了我的日期。請幫我如何編寫排序功能
from django.db import models
class Aaa(models.Model):
fields = models.IntegerField()
class Meta:
app_label = 'project'
我建議有一個長期,集中閱讀文檔,尤其是: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'