Confused about ContentType

18 views
Skip to first unread message

Robin Lery

unread,
Mar 5, 2014, 5:15:07 AM3/5/14
to django...@googlegroups.com
Hello,

Suppose this is a model for a user's photo:

class Photo(models.Model):
        user = models.ForeignKey(User)
title = models.CharField()
image = models.ImageField()
pub_date = models.DateTimeFied(auto_now=True, auto_now_add=pub_date)
update = models.DateTimeFied(auto_now=False, auto_now_add=True)

This is another model for user's status:

class Status(models.Model):
        user = models.ForeignKey(User)
tweet = models.TextFied()
pub_date = models.DateTimeFied(auto_now=True, auto_now_add=pub_date)

Now, this is a model for all the feeds of a user:

class StreamItem(models.Model):
user = models.ForeignKey(User)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type','object_id')

1. In the above class 'StreamItem', is the content_type the data_type of the instance?

2. What is object_id? Is it the pk of the instance or the pk for that StramItem instance? 

3. Lastly, is how do I get the pub_date of the above two class instance (Photo and Status) and initialize it to the StreamItem instance?

I hope I made myself clear. I really need to know about content types. I will really appreciate if you could help me understand.

Thank you.
Reply all
Reply to author
Forward
0 new messages