Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Zone: add ordering
  • Loading branch information
japsu committed Sep 10, 2019
1 parent 685b3e6 commit beb5e31
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion paikkala/forms.py
Expand Up @@ -47,7 +47,7 @@ def add_contact_fields(self):

def mangle_zone_field(self):
zone_field = self.fields['zone']
zone_field.queryset = self.instance.zones.all().order_by('name')
zone_field.queryset = self.instance.zones.all().order_by('ordering', 'name')

if isinstance(zone_field, ReservationZoneChoiceField):
# This additional magic is required because widgets don't have access to their
Expand Down
22 changes: 22 additions & 0 deletions paikkala/migrations/0016_zone_ordering.py
@@ -0,0 +1,22 @@
# Generated by Django 2.0.8 on 2019-09-10 12:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('paikkala', '0015_contact_and_hidden_seats'),
]

operations = [
migrations.AlterModelOptions(
name='zone',
options={'ordering': ('room', 'ordering', 'name')},
),
migrations.AddField(
model_name='zone',
name='ordering',
field=models.IntegerField(default=0, help_text='Smallest first'),
),
]
2 changes: 2 additions & 0 deletions paikkala/models/zones.py
Expand Up @@ -25,9 +25,11 @@ class Zone(models.Model):
room = models.ForeignKey('paikkala.Room', on_delete=models.PROTECT)
name = models.CharField(max_length=100)
capacity = models.IntegerField(editable=False, default=0)
ordering = models.IntegerField(default=0, help_text='Smallest first')

class Meta:
unique_together = (('room', 'name',),)
ordering = ('room', 'ordering', 'name')

def __str__(self):
return '{room} / {name}'.format(room=self.room.name, name=self.name)
Expand Down

0 comments on commit beb5e31

Please sign in to comment.