diff options
Diffstat (limited to 'apps/notes/models.py')
-rw-r--r-- | apps/notes/models.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/apps/notes/models.py b/apps/notes/models.py index 9dc4f13..bfcb8ba 100644 --- a/apps/notes/models.py +++ b/apps/notes/models.py @@ -19,7 +19,7 @@ from taggit.models import TagBase, GenericTaggedItemBase class LuxTag(TagBase): - color_rgb = models.CharField(max_length=20, null=True, blank=True) + color_rgb = models.CharField(max_length=20, blank=True) class Meta: verbose_name = _("Tag") @@ -34,16 +34,24 @@ class TaggedNotes(GenericTaggedItemBase): tag = models.ForeignKey(LuxTag, related_name="%(app_label)s_%(class)s_items", on_delete=models.CASCADE) +class NotebookManager(models.Manager): + def get_queryset(self): + return super().get_queryset().exclude(name='Trash') + + class Notebook(models.Model): """ Notebook model for Notes """ unique_id = models.UUIDField(default=uuid.uuid4, editable=False) owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) name = models.CharField(max_length=250) - color_rgb = models.CharField(max_length=20, null=True, blank=True) + color_rgb = models.CharField(max_length=20, blank=True) slug = models.SlugField(blank=True) date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) + include_trash = models.Manager() + objects = NotebookManager() # The default manager never shows the Notebook 'Trash' + class Meta: unique_together = ("owner", "name") @@ -69,21 +77,29 @@ class Notebook(models.Model): return rgba +class NoteManager(models.Manager): + def get_queryset(self): + return super().get_queryset().exclude(notebook__name='Trash') + + class Note(models.Model): unique_id = models.UUIDField(default=uuid.uuid4, editable=False) owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) title = models.CharField(max_length=250) - body_text = models.TextField(null=True) - body_html = models.TextField(null=True, blank=True) + body_text = models.TextField(blank=True) + body_html = models.TextField(blank=True) body_qjson = JSONField(null=True, blank=True) - url = models.CharField(max_length=250, null=True, blank=True) + url = models.CharField(max_length=250, blank=True) slug = models.SlugField(blank=True) notebook = models.ForeignKey(Notebook, null=True, blank=True, on_delete=models.SET_NULL) tags = TaggableManager(through=TaggedNotes, blank=True, help_text='Tags') is_public = models.BooleanField(default=False) + include_trash = models.Manager() + objects = NoteManager() # The default manager never shows the notes in 'Trash' + class Meta: unique_together = ("owner", "slug") ordering = ("-date_created", "-date_updated") @@ -108,9 +124,9 @@ class Annotation(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) - highlight_text = models.TextField(null=True) - body_text = models.TextField(null=True) - body_html = models.TextField(null=True, blank=True) + highlight_text = models.TextField(blank=True) + body_text = models.TextField(blank=True) + body_html = models.TextField(blank=True) body_qjson = JSONField(null=True, blank=True) note = models.ForeignKey(Note, null=True, blank=True, on_delete=models.SET_NULL) is_public = models.BooleanField(default=False) |