school in current edition

This commit is contained in:
Nikola Kubiczek 2022-12-07 09:01:43 +01:00
parent 7a7ed51b1f
commit 4d1df46558
3 changed files with 34 additions and 0 deletions

View File

@ -122,6 +122,30 @@ class StudentModelAdmin(admin.ModelAdmin):
list_filter = (StudentYearFilter,) list_filter = (StudentYearFilter,)
class SchoolYearFilter(admin.SimpleListFilter):
title = 'aktualna edycja'
parameter_name = 'aktualna edycja'
def lookups(self, request, model_admin):
return (
('Yes', 'Jedynie aktualna edycja'),
)
def queryset(self, request, queryset):
value = self.value()
year = Edition.current().year
if value == 'Yes':
return queryset.filter(identifier__startswith=str(year))
return queryset
@admin.register(School)
class SchoolAdmin(admin.ModelAdmin):
list_display = ('name', 'in_current', 'email', 'phone')
admin.site.register(Student, StudentModelAdmin) admin.site.register(Student, StudentModelAdmin)
admin.site.register(Edition, EditionModelAdmin) admin.site.register(Edition, EditionModelAdmin)

View File

@ -1,6 +1,7 @@
from django.contrib.auth.models import PermissionsMixin from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.db import models, transaction from django.db import models, transaction
from django.contrib import admin
from tinymce.models import HTMLField from tinymce.models import HTMLField
@ -144,6 +145,7 @@ class School(AbstractBaseUser, PermissionsMixin):
def get_short_name(self): def get_short_name(self):
return self.email return self.email
# TODO change this case :<
def updateTeam(self): def updateTeam(self):
with transaction.atomic(): with transaction.atomic():
identifier = f'{Edition.current().year}-{self.id}-' identifier = f'{Edition.current().year}-{self.id}-'
@ -154,6 +156,11 @@ class School(AbstractBaseUser, PermissionsMixin):
school_address=self.address school_address=self.address
) )
@admin.display(description='Bierze udział w aktualnej edycji', boolean=True)
def in_current(self):
identifier = f'{Edition.current().year}-{self.id}-'
return Student.objects.filter(identifier__startswith=identifier).exists()
class Meta: class Meta:
verbose_name = 'Szkoła' verbose_name = 'Szkoła'
verbose_name_plural = 'Szkoły' verbose_name_plural = 'Szkoły'

View File

@ -92,6 +92,9 @@ X_FRAME_OPTIONS = 'SAMEORIGIN'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
} if os.getenv('ENV') == 'dev' else {
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'puchar_lo5', 'NAME': 'puchar_lo5',
'USER': os.getenv('DB_USER'), 'USER': os.getenv('DB_USER'),