Commit 63950b54 authored by Tom van Bussel's avatar Tom van Bussel
Browse files

Setting year of thabloid in admin

parent 27f3126c
from django import forms
from django.contrib import admin
from django.utils import timezone
from .models import Thabloid
from thabloid.models import Thabloid
from utils.snippets import datetime_to_lectureyear
def association_year_choices():
current_year = datetime_to_lectureyear(timezone.now())
choices = []
for year in range(1990, current_year+2):
choices.append((year, '{}-{}'.format(year, year+1)))
choices.reverse()
return choices
class ThabloidAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.initial['year'] = datetime_to_lectureyear(timezone.now())
self.fields['year'] = forms.ChoiceField(
label='Academic year',
choices=association_year_choices()
)
class ThabloidAdmin(admin.ModelAdmin):
list_filter = ('year', )
form = ThabloidAdminForm
list_filter = ('year',)
admin.site.register(Thabloid, ThabloidAdmin)
# Generated by Django 2.0.1 on 2018-03-07 19:47
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('thabloid', '0002_auto_20170129_1449'),
]
operations = [
migrations.AlterField(
model_name='thabloid',
name='year',
field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1990)], verbose_name='academic year'),
),
]
......@@ -17,8 +17,13 @@ def thabloid_filename(instance, filename):
class Thabloid(models.Model):
year = models.IntegerField(validators=[MinValueValidator(1990)])
year = models.IntegerField(
verbose_name='academic year',
validators=[MinValueValidator(1990)]
)
issue = models.IntegerField()
file = models.FileField(
upload_to=thabloid_filename,
validators=[validate_file_extension],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment