TypeError: Cannot resolve keyword 'slug' into field

1,606 views
Skip to first unread message

Brian

unread,
May 17, 2008, 5:46:23 PM5/17/08
to Django users
I've searched for this, but people think it is either fixed or very
hard to reproduce. In my case it is 100% reproducible, and I wonder if
it is my own fault.

I have a model for a mp3 set (a set of mp3s). Individual mp3's are
associated with the set via a Foreign key.

I recently added a slug field to the mp3 after the fact, and I think I
have manually added it to the MySQL database to match what Django
thinks should be there. Now, when I try to edit a mp3 set in the admin
page and hit save, I always get:

TypeError at /django/admin/band/mp3_set/3/
Cannot resolve keyword 'slug' into field. Choices are: mp3, id, date,
title, text

Here are the models:

class Mp3_Set(models.Model):
date = models.DateField(auto_now_add = True, editable = False)
title = models.CharField(max_length = 64)
text = models.TextField()

def __unicode__(self):
return self.title

class Admin:
list_filter = ('date', )
list_display = ('title', 'date')

class Meta:
ordering = ('date', )
verbose_name = "MP3 Set"

class Mp3(models.Model):
mp3_set = models.ForeignKey(Mp3_Set, edit_inline = models.TABULAR,
num_in_admin = 5, num_extra_on_change = 5)
title = models.CharField(max_length = 64, core = True)
desc = models.CharField(max_length = 128, blank = True)
file = models.FileField(upload_to = 'mp3s/%Y/%m/%d/')
slug = models.SlugField(unique = True, prepopulate_from = ('title',
'desc'))

def __unicode__(self):
return self.title

class Admin:
pass

class Meta:
ordering = ('title', )
verbose_name = "MP3"

And here is the export SQL for the two tables:

CREATE TABLE `band_mp3_set` (
`id` int(11) NOT NULL auto_increment,
`date` date NOT NULL,
`title` varchar(64) collate latin1_general_ci NOT NULL,
`text` longtext collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
AUTO_INCREMENT=4 ;

CREATE TABLE `band_mp3` (
`id` int(11) NOT NULL auto_increment,
`mp3_set_id` int(11) NOT NULL,
`title` varchar(64) collate latin1_general_ci NOT NULL,
`desc` varchar(128) collate latin1_general_ci NOT NULL,
`file` varchar(100) collate latin1_general_ci NOT NULL,
`slug` varchar(50) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `band_mp3_slug` (`slug`),
KEY `band_mp3_mp3_set_id` (`mp3_set_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
AUTO_INCREMENT=11 ;


Here is a trace back:
Traceback:
File "C:\Python25\Lib\site-packages\django\core\handlers\base.py" in
get_response
82. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python25\Lib\site-packages\django\contrib\admin\views
\decorators.py" in _checklogin
62. return view_func(request, *args, **kwargs)
File "C:\Python25\Lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "C:\Python25\Lib\site-packages\django\contrib\admin\views
\main.py" in change_stage
334. errors = manipulator.get_validation_errors(new_data)
File "C:\Python25\Lib\site-packages\django\oldforms\__init__.py" in
get_validation_errors
62. errors.update(field.get_validation_errors(new_data))
File "C:\Python25\Lib\site-packages\django\oldforms\__init__.py" in
get_validation_errors
379. self.run_validator(new_data, validator)
File "C:\Python25\Lib\site-packages\django\oldforms\__init__.py" in
run_validator
369. validator(new_data.get(self.field_name, ''),
new_data)
File "C:\Python25\Lib\site-packages\django\utils\functional.py" in
_curried
55. return _curried_func(*(args+moreargs), **dict(kwargs,
**morekwargs))
File "C:\Python25\Lib\site-packages\django\db\models\fields
\__init__.py" in manipulator_validator_unique
47. old_obj = self.manager.get(**{lookup_type: field_data})
File "C:\Python25\Lib\site-packages\django\db\models\manager.py" in
get
69. return self.get_query_set().get(*args, **kwargs)
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in get
261. obj_list = list(clone)
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
__iter__
114. return iter(self._get_data())
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
_get_data
486. self._result_cache = list(self.iterator())
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
iterator
180. select, sql, params = self._get_sql_clause()
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
_get_sql_clause
501. joins2, where2, params2 = self._filters.get_sql(opts)
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
get_sql
723. joins2, where2, params2 = val.get_sql(opts)
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
get_sql
774. return parse_lookup(self.kwargs.items(), opts)
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
parse_lookup
929. joins2, where2, params2 = lookup_inner(path,
lookup_type, value, opts, opts.db_table, None)
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
lookup_inner
1047. raise TypeError, "Cannot resolve keyword '%s' into
field. Choices are: %s" % (name, ", ".join(choices))

Exception Type: TypeError at /django/admin/band/mp3_set/3/
Exception Value: Cannot resolve keyword 'slug' into field. Choices
are: mp3, id, date, title, text


Thanks for any hints.

Karen Tracey

unread,
May 18, 2008, 7:01:02 PM5/18/08
to django...@googlegroups.com

Based on the choices the error message lists, it appears you have added code that tries to access the slug field in an Mp3_Set model instance.  However, you have added the slug field to the other model, Mp3.

Karen

Brian

unread,
May 19, 2008, 12:11:17 AM5/19/08
to Django users
On May 18, 6:01 pm, "Karen Tracey" <kmtra...@gmail.com> wrote:
>
> Based on the choices the error message lists, it appears you have added code
> that tries to access the slug field in an Mp3_Set model instance. However,
> you have added the slug field to the other model, Mp3.
>
> Karen

Where would that code be? This is in the admin page when I am editing
an Mp3_Set. The Mp3's appear inline on that page. I can edit Mp3's on
their own admin page just fine. Thanks.

Karen Tracey

unread,
May 19, 2008, 9:19:08 AM5/19/08
to django...@googlegroups.com

Ah, sorry, I missed the fact that it was admin causing the error.  The error looks to be in the old manipulator/validator code for the slugfield.  With newforms-admin this code is on its way out, so unlikely to get much attention for figuring out what exactly is going wrong.  I tried your models under newforms-admin, and I don't see any problem there with saving an Mp3_Set with inline-edited Mp3 instances. So one option for you would be to convert to newforms-admin.  Note that the prepoulate_from bit for the slug field doesn't work for inline-edited models (in either old or new admin case), see:

http://code.djangoproject.com/ticket/957

Karen

Brian

unread,
May 19, 2008, 9:48:59 AM5/19/08
to Django users
On May 19, 8:19 am, "Karen Tracey" <kmtra...@gmail.com> wrote:
> Ah, sorry, I missed the fact that it was admin causing the error.  The error
> looks to be in the old manipulator/validator code for the slugfield.  With
> newforms-admin this code is on its way out, so unlikely to get much
> attention for figuring out what exactly is going wrong.  I tried your models
> under newforms-admin, and I don't see any problem there with saving an
> Mp3_Set with inline-edited Mp3 instances. So one option for you would be to
> convert to newforms-admin.  

How does one cut over to newforms-admin? I didn't see anything about
that on the docs page.

>Note that the prepoulate_from bit for the slug
> field doesn't work for inline-edited models (in either old or new admin
> case), see:
>
> http://code.djangoproject.com/ticket/957

Yes I have noticed it doesn't reliably work.

Thanks again.

Karen Tracey

unread,
May 19, 2008, 10:05:28 AM5/19/08
to django...@googlegroups.com
On Mon, May 19, 2008 at 9:48 AM, Brian <bgn...@gmail.com> wrote:

On May 19, 8:19 am, "Karen Tracey" <kmtra...@gmail.com> wrote:
> Ah, sorry, I missed the fact that it was admin causing the error.  The error
> looks to be in the old manipulator/validator code for the slugfield.  With
> newforms-admin this code is on its way out, so unlikely to get much
> attention for figuring out what exactly is going wrong.  I tried your models
> under newforms-admin, and I don't see any problem there with saving an
> Mp3_Set with inline-edited Mp3 instances. So one option for you would be to
> convert to newforms-admin.  

How does one cut over to newforms-admin? I didn't see anything about
that on the docs page.

Reply all
Reply to author
Forward
0 new messages