sorting - Cannot sort foreign keys fields in django admin list -
i'm trying sort foreign keys in change list not working yet. (i have seen when clicking sorting in table, gets wrong when foreign keys)
class productvariantadmin(admin.modeladmin): fields=["product", "test_software", "test_variables", "name", "description"] list_display = ("name", "product", "test_software", "test_variables", "description") search_fields = ["name"] form = productvariantform def formfield_for_foreignkey(self, db_field, request, **kwargs): print db_field.name if db_field.name == "test_software_id": kwargs["queryset"] = testsoftware.objects.all().order_by('name') return super(productvariantadmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
i have seen work formfield_for_foreignkey, still list sorted id , not name of foreign key.
any solution that? i'm using django 1.4.1.
formfield_for_foreignkey
overrides drop down menu.
what want order in model's meta
:
class testsoftware(models.model): class meta: ordering = ['name']
Comments
Post a Comment