python - django model admin add form gets stuck -
consider this
@admin.register(personal, site=admin_site) class personaladmin(admin.modeladmin): form = changepersonalform add_form = addpersonalform def get_form(self, request, obj=none, **kwargs): if not obj: self.form = self.add_form return super(personaladmin, self).get_form(request, obj, **kwargs)
the first time try creating
or changing
object, work fine. but, after create
object, every time try change
object, add_form
instead of form
i fixed adding else block
@admin.register(personal, site=admin_site) class personaladmin(admin.modeladmin): change_form = changepersonalform add_form = addpersonalform def get_form(self, request, obj=none, **kwargs): if not obj: self.form = self.add_form else: self.form = self.change_form return super(personaladmin, self).get_form(request, obj, **kwargs)
as if there sort of class
caching.
anyone knows why?
all in django templates. when assigning custom form admin-site form not change functionality of how django receives data changing template used in each request, when creating , updating first time ok, once assigned custom form used default actions of form. it's necessary contemplate 2 cases doing it's necessary reassign default template (form) using , not remain in previous template (add_form). django internally. ref https://github.com/django/django/blob/master/django/contrib/admin/options.py#l1006
note: if use custom form not use "form" variable reassing custom form, instead form use change_form
@admin.register(personal, site=admin_site) class personaladmin(admin.modeladmin): change_form = changepersonalform add_form = addpersonalform def get_form(self, request, obj=none, **kwargs): if not obj: self.form = self.add_form else: self.form = self.change_form return super(personaladmin, self).get_form(request, obj, **kwargs)
Comments
Post a Comment