Django ModelAdmin field syntax simplifier.
Project description
Django ModelAdmin field syntax simplifier.
Common django admin field customization syntax for looks like this.
class FileAdmin(ModelAdmin) list_display = ('name', 'human_size') def human_size(self, obj): return filesizeformat(obj.size) human_size.short_description = 'size' human_size.admin_order_field = 'size'
This lib allows allows to sorten it and make it reusable.
class FileAdmin(ModelAdmin) list_display = ('name', 'human_size') human_size = AdminField('size', filesizeformat)
Inheritance
You can create some reusable fields, for multipy usage.
class AdminSizeField(AdminFieldBase): DEFAULT_FIELD = 'size' method = staticmethod(human_size) class FileAdmin(ModelAdmin) list_display = ('name', 'human_size') human_size = AdminSizeField()
Attributes
By default, ‘short description’ and ‘admin order field’ will be taken from the field name. But you can overide it by kwargs.
class FileAdmin(ModelAdmin) list_display = ('name', 'human_size') human_size = AdminField('size', filesizeformat, short_description='real size', allow_tags=True)
Foreign keys
By default ModelAdmin doesn’t allow you to use foreign keys in list_display. Feel free to do it with AdminField. It will atomaticaly optain description and sort field.
class UserFileAdmin(ModelAdmin) list_display = ('name', 'file__size') file__size = AdminField('file__size', filesizeformat)
Don’t forget to select related model.
class UserFileAdmin(ModelAdmin) select_related = ['file'] list_display = ('name', 'file__size') file__size = AdminField('file__size', filesizeformat) def queryset(self, request): return super(AdminModelSelectRelated, self).queryset(request).select_related(*self.select_related)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-admin-field-0.0.2.tar.gz
.
File metadata
- Download URL: django-admin-field-0.0.2.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a632032ee227229931bd61382febc9cbacce5b022e116b378feda0ac24fe29e |
|
MD5 | 935b9345026603407911c6cc48090670 |
|
BLAKE2b-256 | 6b133c5b4cd6abed0f3647923bf25316f92c2a527b78fde2132059f86e51f31b |