Opened 11 years ago

Closed 11 years ago

Last modified 7 years ago

#8027 closed (fixed)

wrong fieldset validation?

Reported by: Harut Owned by: Jacob
Component: Forms Version: master
Severity: Keywords: newforms
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


class WYSIWYGForm(forms.ModelForm): 
    class Media: 
        js = (
            ''.join((MEDIA_URL, "admin/js/textareas.js")),

class AdminWYSIWYG(admin.ModelAdmin):
    form = WYSIWYGForm

class SongAdmin(AdminWYSIWYG):
    fieldsets = (
        (None, {
            'fields': ('title', 'slug', 'group', 'author_l', 'co_author', 'author_v', 'lyrics')
        ('Перевод и аккорды', {
            'classes': ('collapse',),
            'fields': ('accords', 'translation')
    prepopulated_fields = {"slug": ("title",)}

This construction raises error in, line 182:

        for field in flatten_fieldsets(cls.fieldsets):
            _check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field)

But without validation it works correctly. May be, there is possible to off checking fields if form is subclass of ModelForm? Or validate it in other way?


        if not issubclass(cls.form, BaseModelForm):
            for field in flatten_fieldsets(cls.fieldsets):
                _check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field)

May be, I do something wrong?

Change History (7)

comment:1 Changed 11 years ago by Michael Radziej

milestone: 1.0 beta
Triage Stage: UnreviewedAccepted

comment:2 Changed 11 years ago by Brian Rosner

Can you please provide some more information about this. Specifically your model and the exact traceback. As a side note, there is no reason to join the MEDIA_URL to relative media paths in the inner Media definition, it is done by default.

comment:3 Changed 11 years ago by Harut

Thanks for note.


Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.0-alpha-SVN-8135
Python Version: 2.5.2
Installed Applications:
Installed Middleware:

File "/usr/lib/python2.5/site-packages/django/core/handlers/" in get_response
  78.                     request.path_info)
File "/usr/lib/python2.5/site-packages/django/core/" in resolve
  238.             for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/python2.5/site-packages/django/core/" in _get_urlconf_module
  258.             self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
File "/home/fhen/djangos/dm/../dm/" in <module>
  6. admin.autodiscover()
File "/usr/lib/python2.5/site-packages/django/contrib/admin/" in autodiscover
  14.             __import__("%s.admin" % app)
File "/home/fhen/djangos/dm/discography/" in <module>
  49., SongAdmin)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/" in register
  94.             validate(admin_class, model)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/" in validate
  15.     _validate_base(cls, model)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/" in _validate_base
  184.             _check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/" in _check_form_field_existsw
  149.         return _check_form_field_exists(cls, model, opts, label, field)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/" in _check_form_field_exists
  263.                 "is missing from the form." % (cls.__name__, label, field))

Exception Type: ImproperlyConfigured at /admin/
Exception Value: `SongAdmin.fieldsets[3][1]['fields']` refers to field `title` that is missing from the form.


class Song(models.Model):
    title = models.CharField(u'название', max_length=150)
    slug = models.SlugField(u'слаг')
    author_l = models.ManyToManyField(Person, verbose_name=u'автор', related_name='lirycs_wrote', blank=True, null=True)
    co_author = models.CharField(u'соавтор', max_length=250, blank=True, null=True)
    author_v = models.ManyToManyField(Person, verbose_name=u'вокал', related_name='vokalists', blank=True, null=True)
    group = models.ForeignKey(Performer, verbose_name=u'группа (в т.ч. и сольные)', blank=True, null=True)
    lyrics = models.TextField(u'текст песни', blank=True, null=True)
    accords = models.TextField(u'аккорды', blank=True)
    translation = models.TextField(u'перевод песни', blank=True)
    class Meta:
        ordering = ('title',)

    def __unicode__(self):
        return self.title

As I understand, during the field checking ModelForm is not instantianted and has no fields.

comment:4 Changed 11 years ago by Brian Rosner

milestone: 1.0 beta1.0

comment:5 Changed 11 years ago by Jacob

Owner: changed from nobody to Jacob
Status: newassigned

comment:6 Changed 11 years ago by Jacob

Resolution: fixed
Status: assignedclosed

(In [8662]) Fixed #8027: correctly validate fields/fieldsets in ModelAdmin validation when using custom ModelForms.

comment:7 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top