ItemList options¶
ItemList is very similar to django’s ModelAdmin. It renders a list of objects returned by Widget values method. The most awesome thing about this widget is it can handle almost everything: a list of model objects, namedtuples, dictionaries and sequences (generators are not sequences).
class ModelItemList(widgets.ItemList):
model = Model
queryset = model.active_objects.all()
list_display = ('pk', 'field', 'get_foo')
list_display_links = ('field', 'get_foo')
template_name = 'my_custom_template.html'
def get_foo(self, obj):
return 'foo'
get_foo.allow_tags = True
get_foo.short_description = 'Foo!'
list_displayFor model objects, namedtuples and dictionaries,
list_displayis a list of fields or keys of object. For sequences index of each item inlist_displaybecomes a key in object, i.e.dict(zip(list_display, sequence)).Widget’s and model’s class methods can be used in
list_displayjust like inModelAdmin.list_display``_. They must take an extra parameter for the object returned by ``values. They may have two propertiesallow_tags(TrueorFalseto allow or escape html tags) andshort_description(for column name).list_display_linksKeys or fields should be linked to object’s admin page. If nothing is provided
ItemListwill try to link the first column.Note
If
ItemList.valuesmethod doesn’t return a list of model objects andItemList.modelis not defined, therefore there is no way left to build object’s url.empty_message- If no items returned by
valuesthis message is displayed. sortableSet
Trueto make the list sortable.Note
ModelAdmingets sorted data from the database andItemListuses Sortable.js_ to sort rows in browser and it’s not aware about fields data-type. That means you should be careful with sorting stuff like this:%d.%m.