diff options
Diffstat (limited to 'apps/notes/models.py')
-rw-r--r-- | apps/notes/models.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/apps/notes/models.py b/apps/notes/models.py new file mode 100644 index 0000000..aeb3bb3 --- /dev/null +++ b/apps/notes/models.py @@ -0,0 +1,38 @@ +from django.db import models +from django.utils import timezone +from django.template.defaultfilters import slugify + +from taggit.managers import TaggableManager + +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) + + def __str__(self): + return self.name + + +class Note(models.Model): + created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + 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) + 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') + + def __str__(self): + return self.title + + 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] + self.date_updated = timezone.now() + super(Note, self).save() |