etianen/django-reversion — Issue #102: Reversion fails when multiple proxy models are registered
Author: thedrow
Created: 2011-11-07 19:17:15+00:00
State: open

I get the following traceback:

```Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/

Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'omerkatz.website',
'dojango',
'disqus',
'blog',
'reversion']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'dojango.middleware.DojoCollector')

Traceback:
File "C:\Python27\environments\website\lib\site-packages\django\core\handlers\base.py" in get_response
101. request.path_info)
File "C:\Python27\environments\website\lib\site-packages\django\core\urlresolvers.py" in resolve
250. for pattern in self.url_patterns:
File "C:\Python27\environments\website\lib\site-packages\django\core\urlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python27\environments\website\lib\site-packages\django\core\urlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python27\environments\website\lib\site-packages\django\utils\importlib.py" in import_module
35. __import__(name)
File "C:\Users\Omer\PycharmProjects\omerkatz\urls.py" in
6. admin.autodiscover()
File "C:\Python27\environments\website\lib\site-packages\django\contrib\admin\__init__.py" in autodiscover
26. import_module('%s.admin' % app)
File "C:\Python27\environments\website\lib\site-packages\django\utils\importlib.py" in import_module
35. __import__(name)
File "C:\Users\Omer\PycharmProjects\omerkatz\blog\admin.py" in
60. admin.site.register(DraftPost, DraftPostModelAdmin)
File "C:\Python27\environments\website\lib\site-packages\django\contrib\admin\sites.py" in register
100. self._registry[model] = admin_class(model, self)
File "C:\Python27\environments\website\lib\site-packages\reversion\admin.py" in __init__
84. self._autoregister(self.model, inline_fields)
File "C:\Python27\environments\website\lib\site-packages\reversion\admin.py" in _autoregister
57. follow.append(field.name)

Exception Type: AttributeError at /admin/
Exception Value: 'NoneType' object has no attribute 'name'
```

Here are the models:

```python
from datetime import datetime
from django.db import models
from django.core.urlresolvers import reverse
from autoslug.fields import AutoSlugField
import tagging
from tagging.fields import TagField
from blog.managers import PublishedPostsManager, DraftPostsManager, ScheduledPostsManager

class PostUrlMixin(object):
def get_absolute_url(self):
if self.is_published:
return reverse('blog:post', args = [self.published_on.year, self.published_on.month, self.published_on.day, self.slug])
else:
return reverse('blog:post-by-id', args = [self.id])

class Post(models.Model, PostUrlMixin):
id = models.AutoField(primary_key=True, db_index=True, unique=True)
slug = AutoSlugField(populate_from='title', unique=True, editable=True, max_length=60)
title = models.CharField(blank=False, null=False, max_length=255)
content = models.TextField(blank=True, null=True)
is_published = models.BooleanField(default = False, null=False)
created_on = models.DateField(auto_now = True)
published_on = models.DateField(null=True, blank=True, db_index=True)

tags = TagField()
related_posts = models.ManyToManyField('self', blank=True, null=True)

def publish(self, force_insert=False, force_update=False, using=None):
if self.published_on is None:
self.published_on = datetime.now()

super(Post, self).save(force_insert, force_update, using)

def unpublish(self, force_insert=False, force_update=False, using=None):
self.published_on = None

super(Post, self).save(force_insert, force_update, using)

def save(self, force_insert=False, force_update=False, using=None):
if self.is_published:
self.publish(force_insert=False, force_update=False, using=None)
else:
self.unpublish(force_insert=False, force_update=False, using=None)

def __unicode__(self):
return self.title

class PublishedPost(Post, PostUrlMixin):
class Meta:
ordering = ['-published_on']
get_latest_by = 'published_on'
proxy = True

objects = PublishedPostsManager()

def delete(self, using=None):
self.unpublish()

class ScheduledPost(Post, PostUrlMixin):
class Meta:
ordering = ['-created_on']
get_latest_by = 'created_on'
proxy = True

objects = ScheduledPostsManager()

def save(self, force_insert=False, force_update=False, using=None):
super(Post, self).save(force_insert, force_update, using)

class DraftPost(Post, PostUrlMixin):
class Meta:
ordering = ['-created_on']
get_latest_by = 'created_on'
proxy = True

objects = DraftPostsManager()

tagging.register(Post, tag_descriptor_attr='post_tags')
```

When I register one of the proxy models to the admin like this admin.site.register(DraftPost, DraftPostModelAdmin) I get the afromentioned traceback.
Am I doing something wrong? Or is it reversion that fails here?