django - commenting app for all other apps

27 views
Skip to first unread message

Robin Lery

unread,
Mar 2, 2014, 5:00:01 AM3/2/14
to django...@googlegroups.com
I have an app for forum. It has three classes Tag, Question and Answer.

models:

    class Tag(models.Model):
        tag_name = models.CharField(max_length=100)
        timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
        updated = models.DateTimeField(auto_now_add=True, auto_now=False)
        description = models.TextField()
        
        def __unicode__(self):
            return smart_unicode(self.tag_name)
        
    class Question(models.Model):
        short_description = models.CharField(max_length=250)
        description = models.TextField()
        asked_by = models.ForeignKey(User)
        tags = models.ManyToManyField(Tag)
        timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
        updated = models.DateTimeField(auto_now_add=True, auto_now=False)
        
        def __unicode__(self):
            return smart_unicode(self.short_description)
        
    class Answer(models.Model):
        description = models.TextField()
        for_question = models.ForeignKey(Question)
        timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
        updated = models.DateTimeField(auto_now_add=True, auto_now=False)
        
        def __unicode__(self):
            return smart_unicode(self.description)

I also want to have comments for Question, Answers and also for other parts of my apps. What is the best way to achieve this? I mean, what is the right way to design the django models for this use case? Do I have to use content types for this? Please guide me how to achieve the above mentioned. Your help will be much appreciated. Thank you.

Camilo Torres

unread,
Mar 2, 2014, 6:38:25 PM3/2/14
to django...@googlegroups.com
On Sunday, March 2, 2014 5:30:01 AM UTC-4:30, Robin Lery wrote:
I have an app for forum. It has three classes Tag, Question and Answer.

I also want to have comments for Question, Answers and also for other parts of my apps. What is the best way to achieve this? I mean, what is the right way to design the django models for this use case? Do I have to use content types for this?

You can use multiple table inheritance. See this question and study how a similar case like yours was solved in another domain, but with the same need for comments:


Regards,
Camilo
Reply all
Reply to author
Forward
0 new messages