python - How do I call a model method in django ModelAdmin fieldsets? -
i want display embedded map on admin form when info exists in db. have next code:
models.py
class address(models.model): address = models.charfield() def address_2_html(self): if self.address: # homecoming html embedded map using entered address. homecoming embedded_map_html else: homecoming '' address_2_html.allow_tags = true
admin.py
class addressadmin(admin.modeladmin): fieldsets = [(label, {'fields': ['address','address_2_html']}),]
this doesn't work. error:
'addressadmin.fieldsets[1][1]['fields']' refers field 'address_2_html' missing form.
another thing tried using 'description' alternative 'fieldsets', however, 'address_2_html' not accessible within scope of addressadmin. did succeed @ embedding static map using 'description' cool not cool enough.
like (from memory):
class addressadmin(admin.modeladmin): fieldsets = [(label, {'fields': ['address','address_2_html']}),] readonly_fields = ['address_2_html'] def address_2_html(self, obj): homecoming obj.address_2_html() address_2_html.allow_tags = true address_2_html.short_description = 'address display'
python django django-models django-admin
No comments:
Post a Comment