school in current edition
This commit is contained in:
parent
7a7ed51b1f
commit
4d1df46558
24
app/admin.py
24
app/admin.py
@ -122,6 +122,30 @@ class StudentModelAdmin(admin.ModelAdmin):
|
||||
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(Edition, EditionModelAdmin)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django.contrib.auth.models import PermissionsMixin
|
||||
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
|
||||
from django.db import models, transaction
|
||||
from django.contrib import admin
|
||||
from tinymce.models import HTMLField
|
||||
|
||||
|
||||
@ -144,6 +145,7 @@ class School(AbstractBaseUser, PermissionsMixin):
|
||||
def get_short_name(self):
|
||||
return self.email
|
||||
|
||||
# TODO change this case :<
|
||||
def updateTeam(self):
|
||||
with transaction.atomic():
|
||||
identifier = f'{Edition.current().year}-{self.id}-'
|
||||
@ -154,6 +156,11 @@ class School(AbstractBaseUser, PermissionsMixin):
|
||||
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:
|
||||
verbose_name = 'Szkoła'
|
||||
verbose_name_plural = 'Szkoły'
|
||||
|
@ -92,6 +92,9 @@ X_FRAME_OPTIONS = 'SAMEORIGIN'
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
} if os.getenv('ENV') == 'dev' else {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'puchar_lo5',
|
||||
'USER': os.getenv('DB_USER'),
|
||||
|
Loading…
Reference in New Issue
Block a user