Changeset View
Changeset View
Standalone View
Standalone View
comments/models.py
| Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | def archive_tree(self) -> bool: | ||||
| also affects the comment's parents and replies - the entire tree. | also affects the comment's parents and replies - the entire tree. | ||||
| """ | """ | ||||
| new_archived_status = not self.is_archived | new_archived_status = not self.is_archived | ||||
| tree_pks = self._get_tree_comments_pks() | tree_pks = self._get_tree_comments_pks() | ||||
| Comment.objects.filter(pk__in=tree_pks).update(is_archived=new_archived_status) | Comment.objects.filter(pk__in=tree_pks).update(is_archived=new_archived_status) | ||||
| return new_archived_status | return new_archived_status | ||||
| def get_action_target(self): | |||||
| """Return an object this comment is relevant to, e.g. a blog post or a training section.""" | |||||
| for field in ('section', 'post', 'asset'): | |||||
| target = getattr(self, field, None) | |||||
| if target and target.all(): | |||||
| return target.first() | |||||
| class Like(mixins.CreatedUpdatedMixin, models.Model): | class Like(mixins.CreatedUpdatedMixin, models.Model): | ||||
| class Meta: | class Meta: | ||||
| constraints = [ | constraints = [ | ||||
| models.UniqueConstraint( | models.UniqueConstraint( | ||||
| fields=['user', 'comment'], name='only_one_like_per_comment_and_user' | fields=['user', 'comment'], name='only_one_like_per_comment_and_user' | ||||
| ) | ) | ||||
| ] | ] | ||||
| Show All 13 Lines | |||||