On Mon, Jan 18, 2010 at 3:58 AM, Alessandro Pasotti <[email protected]>wrote:
> Hello,
>
> I would like to have a table with optional pointers to other tables
> items, generic relations would do it fine, the only problem seems to
> be the fact that generic forreign keys don't accept null values.
>
> Any hint or idea about why NOT NULL is enforced in this kind of relations ?
>
What is enforced is what you specify for the underlying database fields.
Modifying the doc example to allow these to be empty:
class TaggedItem(models.Model):
tag = models.SlugField()
content_type = models.ForeignKey(ContentType, null=True, blank=True)
object_id = models.PositiveIntegerField(null=True, blank=True)
content_object = generic.GenericForeignKey('content_type', 'object_id')
allows creation of objects that have no specified contect_object:
>>> from ttt.models import TaggedItem
>>> ti = TaggedItem.objects.create(tag='Empty')
>>> ti
<TaggedItem: Empty>
>>> ti.content_object
>>>
Karen
-- You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

