Skip to content

Commit

Permalink
add created_at, last_modified_at
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Nov 20, 2024
1 parent 7c05252 commit a939727
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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),
),
]
7 changes: 7 additions & 0 deletions src/genlab_bestilling/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a939727

Please sign in to comment.