Commit a2e68c35 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch '277-sorteer-dropdowns-alfabetisch-in-admin' into 'master'

Make sure models are ordered in admin dropdowns

Closes #277

See merge request !314
parents 3cec08af abbec820
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-20 07:37
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('activemembers', '0015_datamigration_lifelong'),
]
operations = [
migrations.AlterModelOptions(
name='committee',
options={'ordering': ('name_nl',), 'verbose_name': 'committee', 'verbose_name_plural': 'committees'},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-21 10:05
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('activemembers', '0016_auto_20170120_0837'),
]
operations = [
migrations.AlterModelOptions(
name='committee',
options={'verbose_name': 'committee', 'verbose_name_plural': 'committees'},
),
]
......@@ -10,16 +10,25 @@ from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from members.models import Member
from utils.translation import ModelTranslateMeta, MultilingualField
from utils.translation import (ModelTranslateMeta, MultilingualField,
localize_attr_name)
logger = logging.getLogger(__name__)
class UnfilteredSortedManager(models.Manager):
"""Returns committees and boards, sorted by name"""
def get_queryset(self):
return (super().get_queryset()
.order_by(localize_attr_name('name')))
class CommitteeManager(models.Manager):
"""Returns committees only"""
def get_queryset(self):
return (super().get_queryset()
.exclude(board__is_board=True))
.exclude(board__is_board=True)
.order_by(localize_attr_name('name')))
class ActiveCommitteeManager(models.Manager):
......@@ -27,13 +36,14 @@ class ActiveCommitteeManager(models.Manager):
def get_queryset(self):
return (super().get_queryset()
.exclude(board__is_board=True)
.exclude(active=False))
.exclude(active=False)
.order_by(localize_attr_name('name')))
class Committee(models.Model, metaclass=ModelTranslateMeta):
"""A committee"""
unfiltered_objects = models.Manager()
unfiltered_objects = UnfilteredSortedManager()
objects = CommitteeManager()
active_committees = ActiveCommitteeManager()
......@@ -98,11 +108,15 @@ class Committee(models.Model, metaclass=ModelTranslateMeta):
class Meta:
verbose_name = _('committee')
verbose_name_plural = _('committees')
# ordering is done in the manager, to sort on a translated field
class BoardManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(is_board=True)
# sorting by descending order by default makes more sense for boards
return (super().get_queryset()
.filter(is_board=True)
.order_by(localize_attr_name('-name')))
class Board(Committee):
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-20 07:37
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('members', '0014_auto_20161109_2128'),
]
operations = [
migrations.AlterModelOptions(
name='member',
options={'ordering': ('user__first_name', 'user__last_name')},
),
]
......@@ -311,6 +311,9 @@ class Member(models.Model):
blank=True,
)
class Meta:
ordering = ('user__first_name', 'user__last_name')
def display_name(self):
pref = self.display_name_preference
if pref == 'nickname' and self.nickname is not None:
......
......@@ -162,27 +162,30 @@ class StatisticsTest(TestCase):
member_types = ["member", "supporter", "honorary"]
current_year = date.today().year
# postgres does not define random access directly on unsorted querysets
members = [member for member in Member.objects.all()]
# one first year student
m = Member.objects.all()[0]
m = members[0]
m.starting_year = current_year
m.save()
# one second year student
m = Member.objects.all()[1]
m = members[1]
m.starting_year = current_year - 1
m.save()
# no third year students
# one fourth year student
m = Member.objects.all()[2]
m = members[2]
m.starting_year = current_year - 3
m.save()
# no fifth year students
# one >5 year student
m = Member.objects.all()[3]
m = members[3]
m.starting_year = current_year - 5
m.save()
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-20 07:37
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('partners', '0007_vacancy_remarks'),
]
operations = [
migrations.AlterModelOptions(
name='partner',
options={'ordering': ('name',)},
),
]
......@@ -61,6 +61,9 @@ class Partner(models.Model):
def get_absolute_url(self):
return reverse('partners:partner', args=(self.slug,))
class Meta:
ordering = ('name', )
class PartnerImage(models.Model):
partner = models.ForeignKey(
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-20 07:37
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('photos', '0005_merge_20160812_1706'),
]
operations = [
migrations.AlterModelOptions(
name='album',
options={'ordering': ('-date', 'title')},
),
migrations.AlterModelOptions(
name='photo',
options={'ordering': ('file',)},
),
]
......@@ -46,6 +46,9 @@ class Photo(models.Model):
image.save(image_path, "JPEG")
self._orig_file = self.file.path
class Meta:
ordering = ('file', )
class Album(models.Model):
title = models.CharField(max_length=200)
......@@ -85,3 +88,6 @@ class Album(models.Model):
def access_token(self):
return hashlib.sha256('{}album{}'.format(settings.SECRET_KEY, self.pk)
.encode('utf-8')).hexdigest()
class Meta:
ordering = ('-date', 'title')
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-20 07:37
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('pizzas', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='product',
options={'ordering': ('name',)},
),
]
......@@ -60,6 +60,9 @@ class Product(models.Model, metaclass=ModelTranslateMeta):
def __str__(self):
return self.name
class Meta:
ordering = ('name', )
class Order(models.Model):
member = models.ForeignKey(
......
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