I have a series of tables which I want to all have an order field. So I made an abstract model:
class OrderedModel(models.Model):
order = models.IntegerField(default=-1)
def _order(self):
pass #ordering widget for changelist_view
_order.allow_tags = True
def save(self,*args,**kwargs):
#set order = 0 if < 0
super(OrderedModel,self).save(*args,**kwargs)
class Meta:
abstract = True
I don't want them to change the "order" field in the change_view, so I make the following ModelAdmin:
class OrderedAdmin(models.ModelAdmin):
list_display = ("__str__","_order","order")
list_editable = ("order",)
readonly_fields = ("order",)
That's fine so long as every model that inherits from OrderedModel doesn't need any more items in list_display, list_editable or readonly_fields. For example, the following would generate an error because order is in list_editable but not list_display:
class Chapter(OrderedModel):
title = models.CharField(max_length=32)
class ChapterAdmin(OrderedAdmin):
list_display = ("title",)
I noticed that there is a get_readonly_fields that I can change to ensure that "order" gets added to readonly_fields, but there's no get_list_display or get_list_editable to over write. Is it possible to do this?