Skip to content

Commit

Permalink
extract cree_le et modifie_le dans un modèle abstrait et partagé
Browse files Browse the repository at this point in the history
  • Loading branch information
kolok committed Jan 20, 2025
1 parent 4f35e12 commit 0ad56a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
10 changes: 10 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models
from django.db.models.functions import Now


class TimestampedModel(models.Model):
cree_le = models.DateTimeField(auto_now_add=True, db_default=Now())
modifie_le = models.DateTimeField(auto_now=True, db_default=Now())

class Meta:
abstract = True
5 changes: 2 additions & 3 deletions data/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.db.models.functions import Now

from core.models import TimestampedModel
from dags.sources.config.shared_constants import (
SUGGESTION_ATRAITER,
SUGGESTION_AVALIDER,
Expand Down Expand Up @@ -40,7 +41,7 @@ class SuggestionAction(models.TextChoices):
SOURCE_SUPPRESSION = SUGGESTION_SOURCE_SUPRESSION, "ingestion de source de données"


class SuggestionCohorte(models.Model):
class SuggestionCohorte(TimestampedModel):
id = models.AutoField(primary_key=True)
# On utilise identifiant car le champ n'est pas utilisé pour résoudre une relation
# en base de données
Expand All @@ -66,8 +67,6 @@ class SuggestionCohorte(models.Model):
blank=True,
verbose_name="Metadata de la cohorte, données statistiques",
)
cree_le = models.DateTimeField(auto_now_add=True, db_default=Now())
modifie_le = models.DateTimeField(auto_now=True, db_default=Now())

@property
def is_source_type(self) -> bool:
Expand Down
6 changes: 2 additions & 4 deletions qfdmo/models/acteur.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from django.core.cache import cache
from django.core.files.images import get_image_dimensions
from django.db.models import Case, Exists, Min, OuterRef, Q, Value, When
from django.db.models.functions import Now
from django.forms import ValidationError, model_to_dict
from django.http import HttpRequest
from django.urls import reverse
from django.utils.functional import cached_property
from unidecode import unidecode

from core.constants import DIGITAL_ACTEUR_CODE
from core.models import TimestampedModel
from dags.sources.config.shared_constants import REPRISE_1POUR0, REPRISE_1POUR1
from qfdmo.models.action import Action, get_action_instances
from qfdmo.models.categorie_objet import SousCategorieObjet
Expand Down Expand Up @@ -268,7 +268,7 @@ def get_queryset(self):
return DisplayedActeurQuerySet(self.model, using=self._db)


class BaseActeur(NomAsNaturalKeyModel):
class BaseActeur(TimestampedModel, NomAsNaturalKeyModel):

class Meta:
abstract = True
Expand Down Expand Up @@ -303,8 +303,6 @@ class Meta:
)
naf_principal = models.CharField(max_length=255, blank=True, null=True)
commentaires = models.TextField(blank=True, null=True)
cree_le = models.DateTimeField(auto_now_add=True, db_default=Now())
modifie_le = models.DateTimeField(auto_now=True, db_default=Now())
horaires_osm = models.CharField(
blank=True, null=True, validators=[validate_opening_hours]
)
Expand Down

0 comments on commit 0ad56a1

Please sign in to comment.