我是Django 1.9的新手,我有一个models.py:
class MyProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Role = ArrayField(models.CharField(max_length=1000), blank=True,null=True)
ContactNumber = models.CharField(max_length=100)
class Meta:
ordering = ('date_joined',)
在这里,我想使用date_joined
的字段User model
订购表格。
当我尝试运行python manage.py makemigrations
时,它给出了如下错误:
SystemCheckError: System check identified some issues:
ERRORS:
projectmanagement.UniservedTeam: (models.E015) 'ordering' refers to the non-existent field 'date_joined'.
我如何实现这一目标?
答案 0 :(得分:5)
设置通用API视图的排序:
http://www.django-rest-framework.org/api-guide/filtering/#orderingfilter
使用:^\/api\/([\w]+)\/([\w]+)\/([a-f0-9]{24})\/?\??.*$
编辑:
你可以像这样指定元类的排序:
ordering = ('user__date_joined', )