From cc04fa555502c95b8dfa16246302b3acccb71024 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 1 Aug 2020 17:49:23 +0200 Subject: [PATCH 1/3] default=timezone.default is better than auto_now_add=True --- apps/activity/models.py | 3 ++- apps/logs/models.py | 3 ++- apps/note/models/notes.py | 3 ++- apps/treasury/models.py | 5 +++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/activity/models.py b/apps/activity/models.py index 2c014ca5..7defb35c 100644 --- a/apps/activity/models.py +++ b/apps/activity/models.py @@ -5,6 +5,7 @@ from datetime import timedelta, datetime from django.contrib.auth.models import User from django.db import models from django.db.models import Q +from django.utils import timezone from django.utils.translation import gettext_lazy as _ from rest_framework.exceptions import ValidationError from note.models import NoteUser, Transaction @@ -118,7 +119,7 @@ class Entry(models.Model): ) time = models.DateTimeField( - auto_now_add=True, + default=timezone.now, verbose_name=_("entry time"), ) diff --git a/apps/logs/models.py b/apps/logs/models.py index 94e2b4ce..e558ea82 100644 --- a/apps/logs/models.py +++ b/apps/logs/models.py @@ -5,6 +5,7 @@ from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.db import models +from django.utils import timezone from django.utils.translation import gettext_lazy as _ @@ -68,7 +69,7 @@ class Changelog(models.Model): timestamp = models.DateTimeField( null=False, blank=False, - auto_now_add=True, + default=timezone.now, name='timestamp', verbose_name=_('timestamp'), ) diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 9282bde9..99818602 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -7,6 +7,7 @@ from django.conf import settings from django.core.exceptions import ValidationError from django.core.validators import RegexValidator from django.db import models +from django.utils import timezone from django.utils.translation import gettext_lazy as _ from polymorphic.models import PolymorphicModel @@ -51,7 +52,7 @@ class Note(PolymorphicModel): ) created_at = models.DateTimeField( verbose_name=_('created at'), - auto_now_add=True, + default=timezone.now, ) class Meta: diff --git a/apps/treasury/models.py b/apps/treasury/models.py index 1e7f2a95..6cfb55c1 100644 --- a/apps/treasury/models.py +++ b/apps/treasury/models.py @@ -6,6 +6,7 @@ from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.db import models from django.db.models import Q +from django.utils import timezone from django.utils.translation import gettext_lazy as _ from note.models import NoteSpecial, SpecialTransaction, MembershipTransaction @@ -53,7 +54,7 @@ class Invoice(models.Model): ) date = models.DateField( - auto_now_add=True, + default=timezone.now, verbose_name=_("Place"), ) @@ -130,7 +131,7 @@ class Remittance(models.Model): """ date = models.DateTimeField( - auto_now_add=True, + default=timezone.now, verbose_name=_("Date"), ) From 36f1a3f0d436344ad34be9b54f475fb1018a102d Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 1 Aug 2020 18:05:31 +0200 Subject: [PATCH 2/3] Activity admin site was missing --- apps/activity/admin.py | 23 ++++++++++++++++++----- apps/activity/models.py | 6 ++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/activity/admin.py b/apps/activity/admin.py index 0529d306..27cabd4e 100644 --- a/apps/activity/admin.py +++ b/apps/activity/admin.py @@ -3,9 +3,11 @@ from django.contrib import admin -from .models import Activity, ActivityType, Guest +from note_kfet.admin import admin_site +from .models import Activity, ActivityType, Guest, Entry +@admin.register(Activity, site=admin_site) class ActivityAdmin(admin.ModelAdmin): """ Admin customisation for Activity @@ -19,6 +21,7 @@ class ActivityAdmin(admin.ModelAdmin): ordering = ['-date_start'] +@admin.register(ActivityType, site=admin_site) class ActivityTypeAdmin(admin.ModelAdmin): """ Admin customisation for ActivityType @@ -26,7 +29,17 @@ class ActivityTypeAdmin(admin.ModelAdmin): list_display = ('name', 'can_invite', 'guest_entry_fee') -# Register your models here. -admin.site.register(Activity, ActivityAdmin) -admin.site.register(ActivityType, ActivityTypeAdmin) -admin.site.register(Guest) +@admin.register(Guest, site=admin_site) +class GuestAdmin(admin.ModelAdmin): + """ + Admin customisation for Guest + """ + list_display = ('last_name', 'first_name', 'activity', 'inviter') + + +@admin.register(Entry, site=admin_site) +class EntryAdmin(admin.ModelAdmin): + """ + Admin customisation for Entry + """ + list_display = ('note', 'activity', 'time', 'guest') diff --git a/apps/activity/models.py b/apps/activity/models.py index 7defb35c..45942cc5 100644 --- a/apps/activity/models.py +++ b/apps/activity/models.py @@ -99,6 +99,9 @@ class Activity(models.Model): verbose_name=_('open'), ) + def __str__(self): + return self.name + class Meta: verbose_name = _("activity") verbose_name_plural = _("activities") @@ -234,6 +237,9 @@ class Guest(models.Model): return super().save(force_insert, force_update, using, update_fields) + def __str__(self): + return self.first_name + " " + self.last_name + class Meta: verbose_name = _("guest") verbose_name_plural = _("guests") From 51fbde23b9ad43c211793d0baa64033720b3fd83 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 1 Aug 2020 18:06:53 +0200 Subject: [PATCH 3/3] Add note consistency check script --- apps/scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/scripts b/apps/scripts index e16629cc..dce51ad2 160000 --- a/apps/scripts +++ b/apps/scripts @@ -1 +1 @@ -Subproject commit e16629cc70c155e4d32244f80684295b459a8a59 +Subproject commit dce51ad26134d396d7cbfca7c63bd2ed391dd969