diff --git a/src/genlab_bestilling/migrations/0006_genrequest_created_at_genrequest_last_modified_at_and_more.py b/src/genlab_bestilling/migrations/0006_genrequest_created_at_genrequest_last_modified_at_and_more.py new file mode 100644 index 0000000..760e62d --- /dev/null +++ b/src/genlab_bestilling/migrations/0006_genrequest_created_at_genrequest_last_modified_at_and_more.py @@ -0,0 +1,44 @@ +# Generated by Django 5.1.1 on 2024-11-20 11:50 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("genlab_bestilling", "0005_rename_station_id_location_code_location_fylke"), + ] + + operations = [ + migrations.AddField( + model_name="genrequest", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="genrequest", + name="last_modified_at", + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name="order", + name="confirmed_at", + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AddField( + model_name="order", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="order", + name="last_modified_at", + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/src/genlab_bestilling/models.py b/src/genlab_bestilling/models.py index 9272b22..2989fd1 100644 --- a/src/genlab_bestilling/models.py +++ b/src/genlab_bestilling/models.py @@ -1,6 +1,7 @@ from django.contrib.postgres.fields.ranges import DateRangeField from django.db import models, transaction from django.urls import reverse +from django.utils import timezone from django.utils.translation import gettext_lazy as _ from polymorphic.models import PolymorphicModel from rest_framework.exceptions import ValidationError @@ -116,6 +117,8 @@ class Genrequest(models.Model): analysis_types = models.ManyToManyField("AnalysisType", blank=True) expected_total_samples = models.IntegerField(null=True, blank=True) analysis_timerange = DateRangeField(null=True, blank=True) + created_at = models.DateTimeField(auto_now_add=True) + last_modified_at = models.DateTimeField(auto_now=True) objects = managers.GenrequestQuerySet.as_manager() @@ -150,12 +153,16 @@ class OrderStatus(models.TextChoices): sample_types = models.ManyToManyField("SampleType", related_name="orders") notes = models.TextField(blank=True, null=True) status = models.CharField(default=OrderStatus.DRAFT, choices=OrderStatus) + created_at = models.DateTimeField(auto_now_add=True) + last_modified_at = models.DateTimeField(auto_now=True) + confirmed_at = models.DateTimeField(null=True, blank=True) tags = TaggableManager(blank=True) objects = managers.OrderManager() def confirm_order(self): self.status = Order.OrderStatus.CONFIRMED + self.confirmed_at = timezone.now() self.save() def clone(self):