默认django管理员用户界面(UI)更改列表视图按'pk'降序排列 我也尝试使用django-tables2这样做,但是连续失败。 这是我的示例代码
我的model.py
Class PersonInfo(models.Model):
i_person = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
city = models.TextField()
my tables.py
class PersonInfoTable(tables.Table):
selection = tables.CheckBoxColumn(accessor="pk")
class Meta:
model = PersonInfo
sequence = ("selection", "...")
my views.py
def person_info(request):
entries_per_page = 50
...
...
...
qs = PersonInfo.objects.all()
table = PersonInfoTable(qs, order_by='-pk')
RequestConfig(request,
paginate={'per_page': entries_per_page}).configure(table)
return render(request, 'my_template.html', {'table': table})
我也尝试过, order_by_field = PersonInfoTable的类Meta中的True。
并尝试过 tables.py中的i_person = tables.Column() table = Person.fo中的PersonInfoTable(qs,order_by =' - i_person')
并尝试过 qs = PersonInfo.objects.all()。order_by('i_person') table = PersonInfoTable(qs)