]>
git.p6c8.net - pcdenotes.git/blob - notes/models.py
70961fd5ca4bf17fefed9e73282f95dbb99596c8
1 from django
.db
import models
2 from django
.contrib
.auth
.models
import User
3 from django
.urls
import reverse
5 # Create your models here.
7 NOTE_STATUS
= ((0, "Draft"),
10 class NoteQuerySet(models
.QuerySet
):
13 class NoteManager(models
.Manager
):
14 def per_year(self
, year
):
15 return super().get_queryset().filter(status
=1, created_at__year
=year
)
17 def per_month(self
, year
, month
):
18 return super().get_queryset().filter(status
=1, created_at__year
=year
, created_at__month
=month
)
20 class Note(models
.Model
):
21 title
= models
.CharField(max_length
=250)
22 slug
= models
.SlugField(max_length
=250, unique
=True)
23 author
= models
.ForeignKey(User
, on_delete
=models
.CASCADE
, related_name
='notes_posted')
24 content
= models
.TextField()
25 status
= models
.IntegerField(choices
=NOTE_STATUS
, default
=0)
27 created_at
= models
.DateTimeField(auto_now_add
=True)
28 updated_at
= models
.DateTimeField(auto_now
=True)
30 objects
= NoteManager()
33 ordering
= ['-created_at']
38 def get_absolute_url(self
):
39 return reverse("notes:note_detail", kwargs
={"note_slug": self
.slug
})
42 return self
.status
== 0
44 def is_published(self
):
45 return self
.status
== 1
patrick-canterino.de