Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#8027 closed (fixed)

wrong fieldset validation?

Reported by: Harut Owned by: Jacob
Component: Forms Version: dev
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

Description

class WYSIWYGForm(forms.ModelForm): 
    class Media: 
        js = (
            ''.join((MEDIA_URL,"js/tiny_mce/tiny_mce.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 validation.py, 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 by Michael Radziej, 16 years ago

milestone: 1.0 beta
Triage Stage: UnreviewedAccepted

comment:2 by Brian Rosner, 16 years ago

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 by Harut, 16 years ago

Thanks for note.

Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.0-alpha-SVN-8135
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'profiles',
 'banners',
 'content',
 'polls',
 'forum',
 'news',
 'discography',
 'filebrowser',
 'pytils',
 'django.contrib.sites',
 'sitetree']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django_fields.captchafield.middleware.request.RequestMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  78.                     request.path_info)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in resolve
  238.             for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
  258.             self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
File "/home/fhen/djangos/dm/../dm/urls.py" in <module>
  6. admin.autodiscover()
File "/usr/lib/python2.5/site-packages/django/contrib/admin/__init__.py" in autodiscover
  14.             __import__("%s.admin" % app)
File "/home/fhen/djangos/dm/discography/admin.py" in <module>
  49. admin.site.register(Song, SongAdmin)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in register
  94.             validate(admin_class, model)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/validation.py" in validate
  15.     _validate_base(cls, model)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/validation.py" in _validate_base
  184.             _check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/validation.py" 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/validation.py" 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.

model:

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:
        verbose_name=u'Песня'
        verbose_name_plural=u'Песни'
        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 by Brian Rosner, 16 years ago

milestone: 1.0 beta1.0

comment:5 by Jacob, 16 years ago

Owner: changed from nobody to Jacob
Status: newassigned

comment:6 by Jacob, 16 years ago

Resolution: fixed
Status: assignedclosed

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

comment:7 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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