80 lines
1.6 KiB
Python
80 lines
1.6 KiB
Python
from django.conf import settings
|
|
from django.db import models
|
|
|
|
|
|
class Note(models.Model):
|
|
class Kind(models.TextChoices):
|
|
TASK = 'task', 'Tâche'
|
|
INFO = 'info', 'Information'
|
|
MEMO = 'memo', 'Mémo'
|
|
SUGGESTION = 'sugg', 'Suggestion'
|
|
|
|
title = models.CharField(
|
|
max_length=160,
|
|
)
|
|
|
|
content = models.TextField(
|
|
blank=True,
|
|
max_length=5000,
|
|
)
|
|
|
|
kind = models.CharField(
|
|
max_length=4,
|
|
choices=Kind.choices,
|
|
default=Kind.MEMO,
|
|
)
|
|
|
|
author = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL,
|
|
on_delete=models.SET_NULL,
|
|
null=True,
|
|
related_name='authored_notes',
|
|
)
|
|
|
|
recipients = models.ManyToManyField(
|
|
settings.AUTH_USER_MODEL,
|
|
blank=True,
|
|
related_name='addressed_notes',
|
|
)
|
|
|
|
is_public = models.BooleanField(
|
|
default=True,
|
|
)
|
|
|
|
completed_at = models.DateTimeField(
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
|
|
created_at = models.DateTimeField(
|
|
auto_now_add=True,
|
|
)
|
|
|
|
updated_at = models.DateTimeField(
|
|
auto_now=True,
|
|
)
|
|
|
|
class Meta:
|
|
ordering = [
|
|
'-created_at',
|
|
'-pk',
|
|
]
|
|
|
|
constraints = [
|
|
models.CheckConstraint(
|
|
condition=(
|
|
models.Q(kind='task')
|
|
| models.Q(
|
|
completed_at__isnull=True,
|
|
)
|
|
),
|
|
name='only_tasks_can_be_completed',
|
|
),
|
|
]
|
|
|
|
@property
|
|
def is_done(self):
|
|
return self.completed_at is not None
|
|
|
|
def __str__(self):
|
|
return self.title |