Docs powiedzieć:dla queryset uporządkowanie danych w django-tables2
Where the table is backed by a model, the database will handle the ordering. Where this is not the case, the Python cmp function is used and the following mechanism is used as a fallback when comparing across different types: ...
Ale czy jest to możliwe w tabeli jest poparte modelu, na kolumnie zwyczaj? na przykład
class MyModel(models.Model):
x = models.IntegerField()
y = models.IntegerField()
def z(self):
return x+y
class MyTable(tables.Table):
z = tables.Column()
class Meta:
model = MyModel
Kiedy próbuję coś takiego, kolumna wyświetla OK, ale po kliknięciu na nagłówek kolumny, aby posortować, otrzymuję ten błąd:
Caught FieldError while rendering: Cannot resolve keyword u'z' into field. Choices are: ...
Podobno to dlatego oo nie znaleziono w tabeli bazy danych.
Czy istnieje sposób obejścia tego?
To jest błąd/brak funkcji w django-tables2. Czy mógłbyś dodać problem do http://github.com/bradleyayers/django-tables2/issues? Udało mi się to ostatnio, ale zapomniałem o tym. –
Należy pamiętać, że [problem został otwarty] (https://github.com/bradleyayers/django-tables2/issues/82), ale ten konkretny problem nie został naprawiony. –