Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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: UI/UX:

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?

Attachments (0)

Change History (7)

comment:1 Changed 6 years ago by mir

  • milestone set to 1.0 beta
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by brosner

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

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 Changed 6 years ago by brosner

  • milestone changed from 1.0 beta to 1.0

comment:5 Changed 6 years ago by jacob

  • Owner changed from nobody to jacob
  • Status changed from new to assigned

comment:6 Changed 6 years ago by jacob

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:7 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.