Friday, April 29, 2011

Multiple databases - unmanaged models - get_absolute_url()

No doubt this is an edge case, but here goes ...

With Django 1.3/Python 2.4 I have an app consisting of unmanaged models in alternate (non-default) database.  Each model has defined get_absolute_url() simply as a fully-qualified (i.e.,external) URL string in which the instance id is substituted.   Everything seems to work fine, except the "View on site" link on the object change pages, which raises a DatabaseError (no such table exists) exception.  The link resolves to the view django.contrib.contenttypes.views.shortcut, which gets the ContentType instance for the object, then re-retrieves the original object (!?) using the ContentType.get_object_for_this_type() method.  Now, I think the problem is that this method uses the database for the contenttypes app instead of the alternate database (see http://code.djangoproject.com/browser/django/tags/releases/1.3/django/contrib/contenttypes/models.py#L102) because it explicitly calls using() with the model state of the ContentType object.

Am I reading the Django code right, or am I doing something wrong?

Thanks,
David

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment