Skip to content

Instantly share code, notes, and snippets.

@alexcabrera
Created January 10, 2010 22:06
Show Gist options
  • Save alexcabrera/273815 to your computer and use it in GitHub Desktop.
Save alexcabrera/273815 to your computer and use it in GitHub Desktop.
# My app will start with creating a generic relationship with any object that notifies it of an update
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
class ActivityStreamItem(models.Model):
actor = models.ForeignKey("... want to populate from another model's inner class ...")
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
# I'd like to make it as easy as possible to integrate with existing apps and models.
# So, ideally it would just require the developer to add an inner class to their models the same way
# django-imagekit handles spec files
from django.db import models
from django.contrib.auth.models import User
class BlogEntry(models.Model):
title = models.CharField(max_length=80)
body = models.TextField()
author = models.ForeignKey(User, related_name = 'blog_author')
class NotifyStream(self):
title = self.title
actor = self.author
# So, in my app's model, how do I a.) know that an event has occurred in the hypothetical blog app,
# and b.) access the inner class from my app's model?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment