feat: datetime_now for transaction
This commit is contained in:
19
app/base/migrations/0003_alter_transaction_time_stamp.py
Normal file
19
app/base/migrations/0003_alter_transaction_time_stamp.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2 on 2023-06-05 18:51
|
||||
|
||||
import app.base.forms.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0002_alter_booking_begin_time'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='transaction',
|
||||
name='time_stamp',
|
||||
field=app.base.forms.fields.DateTimeField(editable=False, verbose_name='Datum / Uhrzeit'),
|
||||
),
|
||||
]
|
||||
@@ -2,6 +2,7 @@ from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
from app.base.forms.fields import CurrencyField, DateTimeField
|
||||
from app.base.forms.utils import datetime_now
|
||||
from app.base.models.account import Account
|
||||
|
||||
|
||||
@@ -13,7 +14,7 @@ class Transaction(models.Model):
|
||||
verbose_name='Zugehörige Zeitbuchung',
|
||||
null=True, blank=True, default=None)
|
||||
description = models.CharField('Beschreibung', max_length=500)
|
||||
time_stamp = DateTimeField('Datum / Uhrzeit', auto_now_add=True)
|
||||
time_stamp = DateTimeField('Datum / Uhrzeit', editable=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Transaktion'
|
||||
@@ -24,3 +25,8 @@ class Transaction(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return f'Transaktion über {self.amount}€ von {self.account}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.pk:
|
||||
self.time_stamp = datetime_now()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user