-
-class UserContent(models.Model):
- user = models.ForeignKey(User, related_name='%(class)ss')
-
- class Meta:
- abstract = True
- app_label = 'forum'
-
-
-class DeletableContent(models.Model):
- deleted = models.BooleanField(default=False)
- deleted_at = models.DateTimeField(null=True, blank=True)
- deleted_by = models.ForeignKey(User, null=True, blank=True, related_name='deleted_%(class)ss')
-
- active = UndeletedObjectManager()
-
- class Meta:
- abstract = True
- app_label = 'forum'
-
- def mark_deleted(self, user):
- if not self.deleted:
- self.deleted = True
- self.deleted_at = datetime.datetime.now()
- self.deleted_by = user
- self.save()
- return True
- else:
- return False
-
- def unmark_deleted(self):
- if self.deleted:
- self.deleted = False
- self.save()
- return True
- else:
- return False
-
-mark_canceled = django.dispatch.Signal(providing_args=['instance'])
-
-class CancelableContent(models.Model):
- canceled = models.BooleanField(default=False)
-
- def cancel(self):
- if not self.canceled:
- self.canceled = True
- self.save()
- mark_canceled.send(sender=self.__class__, instance=self)
- return True
-
- return False
-
- class Meta:
- abstract = True
- app_label = 'forum'
-
-