无法对django-tables2表进行排序。
class MyModel(models.Model):
pid = models.AutoField('id',primary_key = True)
name = models.CharField(max_length = 255,
help_text='The name')
def show_mymodels(request):
""" the view """
table = MyModelTable(MyModel.objects.all())
return render(request,'mymodel.html',{'table':table})
class MyModelTable(tables.Table):
class Meta:
model = MyModel
orderable = Truemymodel.html如下所示:
{% load render_table from django_tables2 %}
{% render_table table %}这会正确地呈现表格,但在浏览器中单击列时不会发生任何反应。除了urld更改http://127.0.0.1:8000/show_mymodel --> http://127.0.0.1:8000/show_mymodel?sort=name之外的其他内容
我到底做错了什么?
发布于 2012-07-05 01:22:34
您需要一个RequestConfig对象,如tutorial中所述
使用RequestConfig的
会自动从
request.GET中提取值,并相应地更新表。这启用了数据排序和分页。
from django_tables2 import RequestConfig
def show_mymodels(request):
table = MyModelTable(MyModel.objects.all())
RequestConfig(request).configure(table)
return render(request, 'mymodel.html', {'table': table})https://stackoverflow.com/questions/11330794
复制相似问题