diff options
Diffstat (limited to 'apps/notes/models.py')
-rw-r--r-- | apps/notes/models.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/apps/notes/models.py b/apps/notes/models.py index aeb3bb3..318b079 100644 --- a/apps/notes/models.py +++ b/apps/notes/models.py @@ -1,6 +1,7 @@ from django.db import models from django.utils import timezone from django.template.defaultfilters import slugify +from django.urls import reverse from taggit.managers import TaggableManager @@ -10,6 +11,8 @@ from django.conf import settings class Folder(models.Model): created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) name = models.CharField(max_length=250) + date_created = models.DateTimeField(blank=True, editable=False) + date_updated = models.DateTimeField(blank=True, editable=False) def __str__(self): return self.name @@ -20,19 +23,26 @@ class Note(models.Model): date_created = models.DateTimeField(blank=True, editable=False) date_updated = models.DateTimeField(blank=True, editable=False) title = models.CharField(max_length=250) - body_markdown = models.TextField(null=True) + body = models.TextField(null=True) + rendered_body = models.TextField(null=True) url = models.CharField(max_length=250) slug = models.SlugField(unique=True, blank=True) folder = models.ForeignKey(Folder, null=True, on_delete=models.SET_NULL) tags = TaggableManager(blank=True, help_text='Tags') + is_public = models.BooleanField(default=False) def __str__(self): return self.title + def get_absolute_url(self): + return reverse("notes:notes-detail", kwargs={"pk": self.pk}) + def save(self, **kwargs): # On save, update timestamps (users updated through admin.py) if not self.id: self.date_created = timezone.now() self.slug = slugify(self.title)[:50] + if not self.title: + self.title = str(self.date_created) self.date_updated = timezone.now() super(Note, self).save() |