python - Display callable attribute from related model in Django admin -


i have next models:

class basemodel(models.model):     def admin_link(self):         url = reverse(             'admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=(self.pk, )         )          return '<a href="{url}">{name}</a>'.format(             url=url, id=str(self)         )     admin_link.allow_tags = true     admin_link.short_description = _('admin link')   class account(basemodel):      pass   class order(basemodel):      account = models.foreignkey(          'base.account', on_delete=models.do_nothing, related_name='orders',          verbose_name=_('account'), null=false      ) 

and created admin model order model:

class orderadminmodel(admin.modeladmin):     fieldsets = [         (_('order'), {'fields': [             'account__admin_link',          ]})     ] 

when go order change page, getiing error:

fielderror @ /admin/base/order/1475d5d6-135f-454e-bec4-a801183dfc5f/change/ unknown field(s) (account__admin_link) specified order. check fields/fieldsets/exclude attributes of class orderadmin.

i don't want write many identical functions in different admin models (i have many relations account model).

can use 1 function display in fields , fields sets?


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -