python - One of my models causes the ...has no attribute '_meta' error when registered to the Admin interface. -
my project consists of 'user' model , 'timer' model.
my timer model looks this:
class usertimer(models.model): timer_user = models.foreignkey('reguser', related_name='user', verbose_name="user", null=true) timer_ispresent = models.booleanfield(_("user present?"), default=false, blank=true) timer_entertime = models.timefield(blank=true, null=true, editable=false) timer_exittime = models.timefield(blank=true, null=true, editable=false) class meta: verbose_name = _('timer') def timerin(self, user): ... return
after registering users model, in same way trying register timer model too:
class timeradmin(admin.stackedinline): fieldsets = ['timer_ispresent'] admin.site.register(usertimer, timeradmin)
but attributeerror: 'nonetype' object has no attribute '_meta'
error.
i realize issue me using foreignkey
in timer, not sure why or how can fixed.
any appreciated.
as can see here
fieldsets list of two-tuples, in each two-tuple represents on admin form page. (a “section” of form.)
the two-tuples in format (name, field_options), name string representing title of fieldset , field_options dictionary of information fieldset, including list of fields displayed in it.
so
fieldsets = ['timer_ispresent']
is not enough.
and, daniel roseman has pointed out, class should not inherit stackedinline.
so put together:
class timeradmin(admin.modeladmin): fieldsets = ( (none, { 'fields': ('timer_ispresent', ) }), )
Comments
Post a Comment