etianen/django-reversion — Issue #95: RegistrationError with GenericRelation
Author: ugoertz
Created: 2011-10-23 20:25:31+00:00
State: open

I get a RegistrationError which I do not really understand in the following way:

I have an application with the following models.py, say:

```
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib import admin
import reversion

class ModelA1(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')

class ModelB(models.Model):
pass

class ModelC(models.Model):
a1 = generic.GenericRelation(ModelA1, content_type_field='content_type', object_id_field='object_id')

class ModelBInline(generic.GenericTabularInline):
model = ModelB

class ModelCAdmin(reversion.VersionAdmin):
inlines = [ ModelBInline, ]

admin.site.register(ModelC, ModelCAdmin)
```

Now I create an instance c of ModelC, and one of ModelA1 pointing to c:

```
(revtest)ug@x220:~/devel/revtest/reversion_test$ python manage.py shell
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
>>> import app1.models as m
>>> c = m.ModelC()
>>> c.save()
>>> a = m.ModelA1()
>>> a.content_object = c
>>> a.save()
>>>
```

Now python manage.py createinitialrevisions gives me

```
...
File "/home/ug/.virtualenvs/revtest/local/lib/python2.7/site-packages/reversion/revisions.py", line 373, in get_adapter
raise RegistrationError, "%r has not been registered with django-reversion" % model
reversion.revisions.RegistrationError: has not been registered with django-reversion
```

The problem seems to be that reversion tries to get an adapter for ModelA1. But why is it trying to follow ModelA1? What I find particularly confusing here is that the problem goes away, if I replace the line inlines = [ ModelBInline, ] in the definition of ModelCAdmin by pass.

I am using reversion 1.5 as installed by pip and Django 1.3.1 with SQlite. I will be glad to provide more information, if there is anything that might be useful.

Am I misunderstanding how things should be done?