I have a table of static data, loaded via initial_data.json. The admin interface apparently displays the data ordered by descending pk; i.e. the records with the largest pk are at the top of list. I would like to reverse this, ideally by using the pk value. Since it's static data, I could add another column for the sort order, but that would essentially duplicate the pk values, or I could, when generating my fixture file, use "pk=len(data)-i" instead of the "pk=i" that I'm currently using. But really, I'd like to just say something like this:
class DataAdmin(admin.ModelAdmin):
ordering = ('row_id',)
I've tried using 'row_id', 'id', and 'pk', without success. Does anyone have any ideas beffore I go source-diving? Thanks!
Put the ordering on the actual model in its Meta class
class YourModel(models.Model):
class Meta:
ordering = ['pk']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With