Callable field in fieldset's field

299 views
Skip to first unread message

Gagan Deep

unread,
Apr 15, 2020, 5:15:48 PM4/15/20
to Django users
Greetings of the day, 

I have defined a model admin inheriting from admin.ModelAdmin class. There is one of the fields which I want to show on the admin dashboard which is a function. I read in Django docs that for a callable function to be a field, it should be added in readonly_fields. So far, it was working great. The problem arose when I mentioned that callable field in the fieldset. 

This worked fine:
class Myadmin(admin.ModelAdmin):
    readonly_fields = ('my_callable_field', )
    fields = ('my_callable_field' )


But, doing this popped Unknown field(s) (my_callable_field) specified for <model>. Check fields/fieldsets/exclude attributes of class Myadmin
class Myadmin(admin.ModelAdmin):
    readonly_fields = ('my_callable_field', )
fieldsets = (
(None, {'fields': ('my_callable_field',)}),
)

I don't understand why this is happening.

Federico Capoano

unread,
Apr 16, 2020, 8:58:36 PM4/16/20
to Django users

Gagan Deep

unread,
Apr 17, 2020, 4:20:04 PM4/17/20
to django...@googlegroups.com
Thanks Federico, it did solved the problem. 



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dd24c6eb-fcaa-41dc-ac78-6f2ba700c5e9%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages