Dev module Carnet_rouge

This commit is contained in:
Ambulance Clerc
2023-05-31 18:45:16 +02:00
parent 5c6ff34ad2
commit 1fe8228d1b
3 changed files with 108 additions and 11 deletions

View File

@@ -4,6 +4,9 @@ from django.conf import settings
from django.contrib.auth.models import Group
from django.utils import timezone
from django.dispatch import receiver
from django.db.models.signals import pre_save
# Create your models here.
class cr_Category(models.Model):
@@ -27,16 +30,30 @@ class cr_Message(models.Model):
sTitle = models.CharField("Titre", max_length=120)
sText = models.TextField("Corps de texte")
dtValidityFrom = models.DateField("Validité depuis",default=timezone.now)
dtValidityTo = models.DateField("Validité jusqu'à", blank=True)
dtValidityTo = models.DateField("Validité jusqu'à", blank=True, null=True)
bEnabled = models.BooleanField("Actif", default=True)
Author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name="Auteur", on_delete=models.SET_NULL, null=True)
sAuthor = models.CharField("Auteur", max_length=120)
sAuthor = models.CharField("auteur string", max_length=120)
Author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name="Auteur", on_delete=models.DO_NOTHING)
dtUpdated = models.DateTimeField('date updated', auto_now=True)
dtCreated = models.DateTimeField('date published', auto_now_add=True)
def calc_read_quotas(self):
obj = self
n_dest = obj.sDestUsers.count('[')
n_readed = obj.sReadedUsers.count('[')
if n_dest == 0:
return "No dest"
print(f"{n_dest}/{n_readed}")
return f"{(n_readed/n_dest)*100}%"
class Meta:
verbose_name = "message"
verbose_name_plural = "messages"
verbose_name_plural = "messages"