From c6499e1841e4d4039f2c0ef9692ae7da86ab32b7 Mon Sep 17 00:00:00 2001 From: richardbarran Date: Sat, 1 Aug 2009 19:28:59 +0000 Subject: [PATCH] Modified Room model to use generic relations (instead of a one-to-one type of relation). git-svn-id: http://django-jqchat.googlecode.com/svn/trunk@7 8369a704-5b4a-11de-992f-fdd7e25b9163 --- jqchat/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jqchat/models.py b/jqchat/models.py index 30a85ec..6334d58 100644 --- a/jqchat/models.py +++ b/jqchat/models.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from django.db import models from django.contrib.auth.models import User +from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes import generic from django.utils.safestring import mark_safe from django.conf import settings @@ -37,6 +39,10 @@ class Room(models.Model): description_modified = models.IntegerField(null=True, editable=False, help_text='Unix timestamp when the description was created or last modified.') last_activity = models.IntegerField(editable=False, help_text='Last activity in the room. Stored as a Unix timestamp.') + # Define generic relation to target object. This is optional. + content_type = models.ForeignKey(ContentType, blank=True, null=True) + object_id = models.PositiveIntegerField(blank=True, null=True) + content_object = generic.GenericForeignKey() def __unicode__(self): return u'%s' % (self.name) @@ -119,7 +125,7 @@ class Message(models.Model): Events: >>> m1 = Message.objects.create_event(user, room, 1) >>> m1.text - u"john has changed the room's description.
" + u'john has changed the description of the lobby.
' Note that there are 2 timestamp fields: - a unix timestamp. -- 2.39.5