I have a model Category which has a ForeignKey to a SimplePage model. null
and blank
are set to True. The problem is, when I edit a Category from the admin interface, I can't change the ForeignKey to ---------
(Which looks like the admin's way of saying None.) The value can be None initially, and I can change it to an actual value through the admin, and I can change to another value, but once it has an actual value I can't change it back to None. (Through the admin, that is.)
Why is this?
UPDATE:
Here's the code for models.py
:
from django.db import models
import tinymce.models
from photologue.models import Photo
from django.utils.translation import ugettext_lazy as _
import multilingual
class SimplePage(models.Model):
slug = models.SlugField(
_('Slug'),
unique=True,
help_text=_('''Unique identifier for URL. Only letters, digits, and -.\
e.g. history-oct-2000 or about''')
)
category = models.ForeignKey('Category',
related_name='items_including_main_page',
blank=True, null=True)
class Translation(multilingual.Translation):
title = models.CharField(_('Title'), max_length=42)
content = tinymce.models.HTMLField(_('Content'), blank=True)
class Admin:
list_display = ('title',)
search_fields = ('title', 'content')
class Meta:
verbose_name = _('Simple page')
verbose_name_plural = _('Simple pages')
__unicode__ = lambda self: self.title
class Category(models.Model):
main_page = models.OneToOneField(
SimplePage,
related_name='_SimplePage__category_which_has_this_as_title',
blank=True,
null=True)
get_title = lambda self: self.main_page.title if self.main_page else u''
get_items = lambda self: \
self.items_including_main_page.exclude(id__exact=self.main_page.id)
__unicode__ = lambda self: self.get_title() or u'Titleless Category'
class Admin:
pass
class Meta:
verbose_name = _('Category')
verbose_name_plural = _('Categories')
And admin.py
:
from sitehelpers.models import *
from django.contrib import admin
import multilingual
class SimplePageAdmin(multilingual.ModelAdmin):
pass
admin.site.register(SimplePage, SimplePageAdmin)
admin.site.register(Category)