Converting from Django 0.91 to Django 0.95

In the 0.95 release code, the model valdiation logic can be a little shakey. In particular, I ran into this traceback today while doing a little code conversion:


Traceback (most recent call last):
  File "manage.py", line 11, in ?
    execute_manager(settings)
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/management.py",
line 1319, in execute_manager
    execute_from_command_line(action_mapping, argv)
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/management.py",
line 1243, in execute_from_command_line
    action_mapping[action]()
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/management.py",
line 1003, in validate
    num_errors = get_validation_errors(outfile)
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/management.py",
line 933, in get_validation_errors
    if not hasattr(cls, fn):
TypeError: hasattr(): attribute name must be string

Turns out this code is much happier in the trunk version than the 0.95 release, but the error ultimately means that I messed up and what was returned in an Admin list_display entry wasn’t a list or tuple, but something else.

In particular, this model code:


class Category(models.Model):
    cat_type = models.CharField(maxlength=25)
    def __str__(self):
        return self.cat_type
    class Admin:
        list_display=('cat_type',),

threw the error – it was that nasty little comma at the end of list_display…

Published by heckj

Developer, author, and life-long student. Writes online at https://rhonabwy.com/.

%d bloggers like this: