Tuesday, May 29, 2012

How to use an optional ForeignKey to sites.Site and admin's "View on site"?

Hi,

I have a model which has a ForeignKey to the Django contrib sites.Site model. This field should be optional.

class MyModel(models.Model):
optional_domain = models.ForeignKey('sites.Site', related_name='optional_site', null=True, blank=True)
...

However, I'm running into a problem on the admin, when I want to use the "View on site" button.
It fires an AttributeError: "'NoneType' object has no attribute 'domain'" with objects for which I leave this field empty.

Is this a bug in /django/contrib/contenttypes/views.py (near line 60), or is there another way to make this work?

Thanks,
Dirk





--
-----------------------------
Dirk van Oosterbosch
http://labs.ixopusada.com
-----------------------------
--




--
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