Mercurial > public > sg101
comparison comments/models.py @ 1206:02181fa5ac9d modernize tip
Update to Django 1.9.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 22 Jan 2025 17:58:16 -0600 |
parents | 5ba2508939f7 |
children |
comparison
equal
deleted
inserted
replaced
1205:510ef3cbf3e6 | 1206:02181fa5ac9d |
---|---|
28 return qs | 28 return qs |
29 | 29 |
30 | 30 |
31 class Comment(models.Model): | 31 class Comment(models.Model): |
32 """My own version of a Comment class that can attach comments to any other model.""" | 32 """My own version of a Comment class that can attach comments to any other model.""" |
33 content_type = models.ForeignKey(ContentType) | 33 content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) |
34 object_id = models.PositiveIntegerField(db_index=True) | 34 object_id = models.PositiveIntegerField(db_index=True) |
35 content_object = GenericForeignKey('content_type', 'object_id') | 35 content_object = GenericForeignKey('content_type', 'object_id') |
36 user = models.ForeignKey(User) | 36 user = models.ForeignKey(User, on_delete=models.CASCADE) |
37 comment = models.TextField(max_length=COMMENT_MAX_LENGTH) | 37 comment = models.TextField(max_length=COMMENT_MAX_LENGTH) |
38 html = models.TextField(blank=True) | 38 html = models.TextField(blank=True) |
39 creation_date = models.DateTimeField() | 39 creation_date = models.DateTimeField() |
40 ip_address = models.GenericIPAddressField('IP Address') | 40 ip_address = models.GenericIPAddressField('IP Address') |
41 is_public = models.BooleanField(default=True, | 41 is_public = models.BooleanField(default=True, |
83 not_removed.boolean = True | 83 not_removed.boolean = True |
84 | 84 |
85 | 85 |
86 class CommentFlag(models.Model): | 86 class CommentFlag(models.Model): |
87 """This model represents a user flagging a comment as inappropriate.""" | 87 """This model represents a user flagging a comment as inappropriate.""" |
88 user = models.ForeignKey(User) | 88 user = models.ForeignKey(User, on_delete=models.CASCADE) |
89 comment = models.ForeignKey(Comment) | 89 comment = models.ForeignKey(Comment, on_delete=models.CASCADE) |
90 flag_date = models.DateTimeField(auto_now_add=True) | 90 flag_date = models.DateTimeField(auto_now_add=True) |
91 | 91 |
92 def __unicode__(self): | 92 def __unicode__(self): |
93 return u'Comment ID %s flagged by %s' % (self.comment.id, self.user.username) | 93 return u'Comment ID %s flagged by %s' % (self.comment.id, self.user.username) |
94 | 94 |