Changes between Initial Version and Version 1 of ListColumns


Ignore:
Timestamp:
Oct 10, 2010, 10:07:36 PM (14 years ago)
Author:
Alex Kamedov
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ListColumns

    v1 v1  
     1
     2== Admin change list view customization with ListColumn ==
     3
     4Related ticket: #8054 Move method properties for admin list customisation to ModelAdmin
     5
     6This ticket adds:
     7
     8 * beatifull API to admin change list customization
     9
     10 * ability to customize and localize 3rd-party application without fork it
     11
     12 * ability to apply custom template filters on field value or model method returned value without any magic
     13
     14 * ability to specify witch field wiil be used in order for column based on model method
     15
     16
     17==== ListColumn API ====
     18
     19Arguments:
     20
     21 * field_name - model field or model method name
     22
     23Keyword arguments:
     24
     25
     26 * header - change list column header. If not provided standard algoritm to header column calculation will be used.
     27
     28 * filter - template filters will be apllied to value on output.
     29
     30 * load_filters - list of required template tags libraries. This libraries will be load before apply template filters to output value.
     31
     32 * order_field - specify witch field will be used to prowide order by this column.
     33
     34
     35
     36==== Example ====
     37
     38Current way to admin change list view customization:
     39
     40{{{
     41class Account(models.Model):
     42    foo = model.BooleanField(...)
     43    bar = model.CharField(...)
     44    baz = model.CharField(...)
     45    bonk = model.CharField(...)
     46    ends = models.DateTimeField()
     47
     48    def get_bar_column(self):
     49        return ...
     50    get_bar_column.allow_tags = True
     51
     52    def timeuntil_ends():
     53        return ...
     54
     55
     56class AccountAdmin(admin.ModelAdmin):
     57    list_display = ['foo', 'get_bar_column', 'baz', 'bonk', 'timeuntil_ends']
     58
     59}}}
     60
     61Proposed way:
     62
     63{{{
     64class Account(models.Model):
     65    foo = model.BooleanField(...)
     66    bar = model.CharField(...)
     67    baz = model.CharField(...)
     68    bonk = model.CharField(...)
     69    ends = models.DateTimeField()
     70
     71    def get_bar(self):
     72        return ...
     73
     74class AccountAdmin(admin.ModelAdmin):
     75    list_display = [
     76        admin.ListColumn('foo', header='Foo Description', filter='boolean'),
     77        admin.ListColumn('get_bar', filter='safe', order_field='bar'),
     78        'baz',
     79        'bonk',
     80        admin.ListColumn('ends', filter='timeuntil', header="Ending in")
     81    ]
     82
     83}}}
Back to Top