newforms-admin weird error ( 'str' object has no attribute '_default_manager' )

45 views
Skip to first unread message

Bram de Jong

unread,
Jul 18, 2008, 10:57:57 AM7/18/08
to django...@googlegroups.com
Hello all,

just updated to latest newforms-admin (r7947) and....


This is the admin for one of my (rather large) models:

class Sound(SocialModel): # SocialModel is a model that defines some
GenericRelation
user = models.ForeignKey(User)
# snip
license = models.ForeignKey(License)
geotag = models.ForeignKey(GeoTag, null=True, blank=True, default=None)
#snip
sources = models.ManyToManyField('self', symmetrical=False,
related_name='remixes', blank=True)
pack = models.ForeignKey('Pack', null=True, blank=True, default=None)
#snip
type = models.CharField(db_index=True, max_length=4,
choices=SOUND_TYPE_CHOICES)
#....

class SoundAdmin(admin.ModelAdmin):
raw_id_fields = ('user', 'pack', 'sources', 'geotag')
list_display = ('id', 'user', 'original_filename', 'license')
list_filter = ('processing_state', 'moderation_state', 'license')
fieldsets = (
(None, {'fields': ('user', 'created', 'modified')}),
('Filenames', {'fields': ('original_path', 'base_filename_slug')}),
('User defined fields', {'fields': ('description', 'license',
'geotag', 'original_filename', 'sources', 'pack')}),
('File properties', {'fields': ('md5', 'type', 'duration',
'bitrate', 'bitdepth', 'samplerate', 'filesize', 'channels')}),
('Moderation', {'fields': ('moderation_state',
'moderation_date', 'moderation_bad_description')}),
('Processing', {'fields': ('processing_state',
'processing_date', 'processing_log')}),
)
admin.site.register(Sound, SoundAdmin)


And this is the error I get when validating:

Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
85. response = callback(request, *callback_args,
**callback_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/decorators.py"
in __call__
66. if self.test_func(request.user):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/middleware.py"
in __get__
5. request._cached_user = get_user(request)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/__init__.py"
in get_user
80. user_id = request.session[SESSION_KEY]
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/sessions/backends/base.py"
in __getitem__
33. return self._session[key]
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/sessions/backends/base.py"
in _get_session
147. self._session_cache = self.load()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/sessions/backends/db.py"
in load
20. expire_date__gt=datetime.datetime.now()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/manager.py"
in get
82. return self.get_query_set().get(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py"
in get
296. clone = self.filter(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py"
in filter
479. return self._filter_or_exclude(False, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py"
in _filter_or_exclude
497. clone.query.add_q(Q(*args, **kwargs))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/query.py"
in add_q
1159. can_reuse=used_aliases)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/query.py"
in add_filter
1037. alias, True, allow_many, can_reuse=can_reuse)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/query.py"
in setup_joins
1197. field, model, direct, m2m = opts.get_field_by_name(name)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/options.py"
in get_field_by_name
274. cache = self.init_name_map()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/options.py"
in init_name_map
300. for f, model in self.get_all_related_m2m_objects_with_model():
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/options.py"
in get_all_related_m2m_objects_with_model
377. cache = self._fill_related_many_to_many_cache()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/options.py"
in _fill_related_many_to_many_cache
391. for klass in get_models():
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/loading.py"
in get_models
136. self._populate()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/loading.py"
in _populate
57. self.load_app(app_name, True)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/loading.py"
in load_app
72. mod = __import__(app_name, {}, {}, ['models'])
File "/Users/bram/Development/nightingale/freesound/sounds/models.py"
in <module>
102. admin.site.register(Sound, SoundAdmin)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in register
81. validate(admin_class, model)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/validation.py"
in validate
15. _validate_base(cls, model)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/validation.py"
in _validate_base
183.
_check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field)
File "/Library/Frameworks/Python.framework/Versions/2.5/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 "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/validation.py"
in _check_form_field_exists
264. fields = fields_for_model(model)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/newforms/models.py"
in fields_for_model
205. formfield = formfield_callback(f)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/newforms/models.py"
in <lambda>
184. def fields_for_model(model, fields=None, exclude=None,
formfield_callback=lambda f: f.formfield()):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/fields/related.py"
in formfield
685. defaults = {'form_class': forms.ModelChoiceField,
'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}

Exception Type: AttributeError at /account/upload/
Exception Value: 'str' object has no attribute '_default_manager'


The error goes away when I remove the fieldsets definition.


Just thought I'd ask here ;)

- Bram

Karen Tracey

unread,
Jul 18, 2008, 11:45:59 AM7/18/08
to django...@googlegroups.com
On Fri, Jul 18, 2008 at 10:57 AM, Bram de Jong <bram....@gmail.com> wrote:

Hello all,

just updated to latest newforms-admin (r7947) and....

Do you know what level you updated from?  That's always handy to know when trying to pinpoint when a problem was introduced.


So it's got something to do with validation.  Do you know if it worked at all after validation of ModelAdmin was added (r7929) and has broken subsequently, or if it broke as soon as ModelAdmin validation was added?


[snip Traceback start]

 184. def fields_for_model(model, fields=None, exclude=None,
formfield_callback=lambda f: f.formfield()):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/fields/related.py"
in formfield
 685.         defaults = {'form_class': forms.ModelChoiceField,
'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}

Exception Type: AttributeError at /account/upload/
Exception Value: 'str' object has no attribute '_default_manager'


The error goes away when I remove the fieldsets definition.

Determining which part of the fieldsets definition generates the error would be helpful.  You might be able to determine it by looking at the local vars in the debug page.  Alternatively you could experiment with removing pieces of it to see which field is causing the error.  Basic fieldsets validation works (I'm sure it's got tests and I have models that use it and still work on current newforms-admin), so it's something specific to your model.  If you could strip your models down to a reasonably simple testcase that displays the error it would be helpful.

Karen

Message has been deleted

Bram de Jong

unread,
Jul 25, 2008, 5:18:12 AM7/25/08
to django...@googlegroups.com
On Fri, Jul 18, 2008 at 5:45 PM, Karen Tracey <kmtr...@gmail.com> wrote:
>
> Determining which part of the fieldsets definition generates the error would
> be helpful. You might be able to determine it by looking at the local vars
> in the debug page. Alternatively you could experiment with removing pieces
> of it to see which field is causing the error. Basic fieldsets validation
> works (I'm sure it's got tests and I have models that use it and still work
> on current newforms-admin), so it's something specific to your model. If
> you could strip your models down to a reasonably simple testcase that
> displays the error it would be helpful.

Sorry for not replying this earlier.
Splitting my admin settings into admin.py modules, and updating to the
latest trunk fixed this problem.


- Bram

Reply all
Reply to author
Forward
0 new messages