Help to create computed or custom fields more friendly and easy way in django
Collection of admin fields, decorators and mixin to help to create computed or custom fields more friendly and easy way
Installation
- Requirements: Django > 1.8 and Python > 3.5
pip install django-admin-easy==0.6.1
For Django < 1.8 or Python 2.x
pip install django-admin-easy==0.4.1
How it Works
When you want to display a field on Django Admin, and this field doesn’t exist in your Model or you need to compute some information, like a Image or Link, you will need to create a method on your ModelAdminClass like this:
from django.contrib import admin
class YourAdmin(admin.ModelAdmin):
fields = ('sum_method', 'some_img', 'is_true')
def sum_method(self, obj):
sum_result = obj.field1 + obj.field2 + obj.field3
return '%s' % sum_result
sum_method.short_description = 'Sum'
sum_method.admin_order_field = 'field1'
sum_method.allow_tags = True
def some_img(self, obj):
return '' % obj.image
some_img.short_description = 'image'
some_img.admin_order_field = 'id'