Admin fields setting raises FieldDoesNotExist

456 views
Skip to first unread message

Justin Myers

unread,
Jul 18, 2008, 8:44:40 PM7/18/08
to Django users
Hello again! Still working on the blogging app I mentioned a couple of
days ago for my student newspaper. It's working on our production
server right now (so some of the other editors can check it out and
make suggestions), though I'll naturally be making some tweaks here
and there.

Right now, though, I'm having a bit of trouble with the admin
interface. I'm trying to put the slugField into a collapsed field
group, which we usually do to keep people from thinking they have to
change it. For whatever reason, though, I keep getting 500s when I try
to set it up this way. The error I'm getting (full traceback after
this message) is "FieldDoesNotExist: Blog has no field named 's'".

Here's the model:

---

class Blog(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
section = models.ForeignKey(Section,db_index=True)
slug = models.SlugField(prepopulate_from=('title',),
help_text="Used for URLs. Autogenerated from title.")

def __unicode__(self):
return self.title

def get_absolute_url(self):
return "/blogs/%s/" % self.slug

class Meta:
ordering = ['title']

class Admin:
list_display = ('title', 'section')
fields = (
(None, {'fields': ('title', 'description', 'section')}),
("Don't touch unless you know what you're doing",
{'fields': ('slug'), 'classes': 'collapse'}),
)

---

If I comment out the four lines at the end (the fields tuple),
everything works fine (except the slug field isn't collapsed), but as
soon as I uncomment them, I get the 500 I mentioned earlier. I'm
probably missing something pretty simple since I'm rather new to this,
but does anyone have any ideas what might be causing this?

Thanks!
-Justin

---

Traceback (most recent call last):

File "/home/themaneater/lib/python2.5/django/core/handlers/base.py",
line 82, in get_response
response = callback(request, *callback_args, **callback_kwargs)

File "/home/themaneater/lib/python2.5/django/contrib/admin/views/
decorators.py", line 62, in _checklogin
return view_func(request, *args, **kwargs)

File "/home/themaneater/lib/python2.5/django/views/decorators/
cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)

File "/home/themaneater/lib/python2.5/django/contrib/admin/views/
main.py", line 406, in change_stage
return render_change_form(model, manipulator, c, change=True)

File "/home/themaneater/lib/python2.5/django/contrib/admin/views/
main.py", line 203, in render_change_form
field_sets = opts.admin.get_field_sets(opts)

File "/home/themaneater/lib/python2.5/django/db/models/options.py",
line 494, in get_field_sets
opts.get_field, fs_options['fields'], description))

File "/home/themaneater/lib/python2.5/django/db/models/options.py",
line 505, in __init__
self.field_lines = [AdminFieldLine(field_locator_func, line_spec)
for line_spec in line_specs]

File "/home/themaneater/lib/python2.5/django/db/models/options.py",
line 525, in __init__
self.fields = [field_locator_func(linespec)]

File "/home/themaneater/lib/python2.5/django/db/models/options.py",
line 236, in get_field
raise FieldDoesNotExist, '%s has no field named %r' %
(self.object_name, name)

FieldDoesNotExist: Blog has no field named 's'

Karen Tracey

unread,
Jul 18, 2008, 9:52:32 PM7/18/08
to django...@googlegroups.com

Python gothca: you've neglected to put a comma after 'slug' in 'fields': ('slug').  Single-element tuples need to have a comma after their one element to force them to be tuples.  In this case the single element is iterable so when code goes to iterate over every element in what it is expecting to be a tuple it iterates over every letter in the string.

Karen

Justin Myers

unread,
Jul 18, 2008, 9:57:24 PM7/18/08
to Django users
Ah, worked perfectly. Thanks so much!
-Justin
Reply all
Reply to author
Forward
0 new messages