0

I am trying to add a new field in django_comment model. According to the documentation, most custom comment models will subclass the CommentAbstractModel model:

from django.db import models
from django_comments.models import CommentAbstractModel

class CommentWithTitle(CommentAbstractModel):
   title = models.CharField(max_length=300)

If I generate a migration, then it adds all the fields into migrations (all fields from comment model plus title field).

And after running migrations, CommentWithTitle table and django_comments table are created. But django_comments would be useless (not in use).

Another approach is to generate the table this way:

from django_comments.models import Comment

class CommentWithTitle(Comment):
    title = models.CharField(max_length=300)

And it generates the migration with one field only with the reference of comment_ptr.

My Question is: which approach is better? I think the first model is good as it has all fields in one table. But that generates the django_model which is not in use at all.

Vicky Leong
  • 1,208
  • 3
  • 12
  • 30
Mark Waugh
  • 423
  • 1
  • 5
  • 10

1 Answers1

0

I would follow the documentation.

Looking at the implementation, Comment is basically just extending CommentAbstractModel with db_table specified.

class Comment(CommentAbstractModel):
    class Meta(CommentAbstractModel.Meta):
        db_table = "django_comments"

I'm suspecting that if you do the second option you mentioned, the migration would throw an error because the db_table will be created twice.

Vicky Leong
  • 1,208
  • 3
  • 12
  • 30