#10005: Incorrect classname assumed in ModelFormMetaClass modelform_factory()
--------------------------------------------+-------------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone: post-1.0
Component: Forms | Version:
Keywords: modelform_factory assumption | Stage: Unreviewed
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
--------------------------------------------+-------------------------------
{{{
debug dump:
c:\python26\lib\site-
packages\django\core\management\commands\runserver.py(61)inner_run
-> run(addr, int(port), handler)
c:\python26\lib\site-packages\django\core\servers\basehttp.py(676)run()
-> httpd.serve_forever()
c:\python26\lib\socketserver.py(226)serve_forever()
-> self._handle_request_noblock()
c:\python26\lib\socketserver.py(281)_handle_request_noblock()
-> self.process_request(request, client_address)
c:\python26\lib\socketserver.py(307)process_request()
-> self.finish_request(request, client_address)
c:\python26\lib\socketserver.py(320)finish_request()
-> self.RequestHandlerClass(request, client_address, self)
c:\python26\lib\site-
packages\django\core\servers\basehttp.py(558)__init__()
-> BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
c:\python26\lib\socketserver.py(615)__init__()
-> self.handle()
c:\python26\lib\site-
packages\django\core\servers\basehttp.py(603)handle()
-> handler.run(self.server.get_app())
c:\python26\lib\site-packages\django\core\servers\basehttp.py(278)run()
-> self.result = application(self.environ, self.start_response)
c:\python26\lib\site-
packages\django\core\servers\basehttp.py(635)__call__()
-> return self.application(environ, start_response)
c:\python26\lib\site-
packages\django\core\handlers\wsgi.py(239)__call__()
-> response = self.get_response(request)
c:\python26\lib\site-
packages\django\core\handlers\base.py(86)get_response()
-> response = callback(request, *callback_args, **callback_kwargs)
c:\python26\lib\site-packages\django\contrib\admin\sites.py(157)root()
-> return self.model_page(request, *url.split('/', 2))
c:\python26\lib\site-
packages\django\views\decorators\cache.py(44)_wrapped_view_func()
-> response = view_func(request, *args, **kwargs)
c:\python26\lib\site-
packages\django\contrib\admin\sites.py(176)model_page()
-> return admin_obj(request, rest_of_url)
c:\python26\lib\site-
packages\django\contrib\admin\options.py(198)__call__()
-> return self.change_view(request, unquote(url))
c:\python26\lib\site-
packages\django\db\transaction.py(238)_commit_on_success()
-> res = func(*args, **kw)
c:\python26\lib\site-
packages\django\contrib\admin\options.py(566)change_view()
-> ModelForm = self.get_form(request, obj)
c:\python26\lib\site-
packages\django\contrib\admin\options.py(278)get_form()
-> return modelform_factory(self.model, **defaults)
> c:\python26\lib\site-
packages\django\forms\models.py(334)modelform_factory()
-> return ModelFormMetaclass(class_name, (form,), {'Meta': Meta,
(Pdb) l 328
323
324 def modelform_factory(model, form=ModelForm, fields=None,
exclude=None,
325 formfield_callback=lambda f:
f.formfield()):
326 # HACK: we should be able to construct a ModelForm without
creating
327 # and passing in a temporary inner class
328 class Meta:
329 pass
330 setattr(Meta, 'model', model)
331 setattr(Meta, 'fields', fields)
332 setattr(Meta, 'exclude', exclude)
333 class_name = model.__name__ + 'Form'
(Pdb) l
334 -> return ModelFormMetaclass(class_name, (form,), {'Meta': Meta,
335 'formfield_callback':
formfield_callback})
336
337
338 # ModelFormSets
##############################################################
339
340 class BaseModelFormSet(BaseFormSet):
341 """
342 A ``FormSet`` for editing a queryset and/or adding new objects
to it.
343 """
344 model = None
(Pdb) p model
<class 'flint.photography.models.Import'>
(Pdb) p form
<class 'flint.photography.admin.ImportAdminForm'>
(Pdb) p class_name
'ImportForm'
[************* INCORRECT ***************]
}}}
yields exception:
{{{
165 def value_from_datadict(self, data, files, name):
166 """
(Pdb)
167 Given a dictionary of data and this widget's name, returns
the value
168 of this widget. Returns None if it's not provided.
169 """
170 import pdb; pdb.set_trace()
171 -> return data.get(name, None)
172
173 def _has_changed(self, initial, data):
174 """
175 Return True if data differs from initial.
176 """
177 # For purposes of seeing whether something has changed,
None is
(Pdb) n
AttributeError: "'ImportForm' object has no attribute 'get'"
> c:\python26\lib\site-
packages\django\forms\widgets.py(171)value_from_datadict()
-> return data.get(name, None)
(Pdb)
}}}
Abridged sample code:
{{{
class ImportAdminAddForm(forms.ModelForm):
class Meta:
model = Import
class ImportAdminForm(forms.ModelForm):
class Meta:
model = Import
class ImportAdminAdd(admin.ModelAdmin):
form = ImportAdminAddForm
class ImportAdmin(admin.ModelAdmin):
form = ImportAdminForm
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/10005>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---