Update location model for happy hour
This commit is contained in:
Robert Einsle 2017-02-25 18:34:28 +01:00
parent 9df1ed5b79
commit 6d16a473bf
3 changed files with 45 additions and 3 deletions

View File

@ -4,10 +4,25 @@ from django import forms
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
class LocationAdminForm(forms.ModelForm):
def clean_happy_hour_end(self):
hh_start = self.cleaned_data['happy_hour_start']
hh_end = self.cleaned_data['happy_hour_end']
if hh_start is None and hh_end is not None:
raise ValidationError('Start und Ende Zeit muss angegeben werden')
if hh_start is not None and hh_end is None:
raise ValidationError('Start und Ende Zeit muss angegeben werden')
if not (hh_end > hh_start):
raise ValidationError('Ende-Zeit muss nach Start-Zeit liegen')
return self.cleaned_data['happy_hour_end']
@admin.register(Location) @admin.register(Location)
class LocationAdmin(admin.ModelAdmin): class LocationAdmin(admin.ModelAdmin):
list_display = ('code', 'name', 'city',) form = LocationAdminForm
fields = ['users', 'code', 'name', 'street', 'plz', 'city', 'phone', 'email', 'url', ] list_display = ('code', 'name', 'city', 'happy_hour_start', 'happy_hour_end')
fields = ['users', 'code', 'happy_hour_start', 'happy_hour_end', 'name', 'street', 'plz', 'city', 'phone', 'email', 'url', ]
@admin.register(Client) @admin.register(Client)

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-25 18:22
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('billard', '0015_auto_20170222_1023'),
]
operations = [
migrations.AddField(
model_name='location',
name='happy_hour_end',
field=models.TimeField(blank=True, null=True, verbose_name='Happy Hour Ende'),
),
migrations.AddField(
model_name='location',
name='happy_hour_start',
field=models.TimeField(blank=True, null=True, verbose_name='Happy Hour Start'),
),
]

View File

@ -37,6 +37,8 @@ class Location(models.Model):
phone = models.CharField(max_length=64, blank=True, null=True, verbose_name="Telefon") phone = models.CharField(max_length=64, blank=True, null=True, verbose_name="Telefon")
email = models.EmailField(blank=True, null=True, verbose_name="Email") email = models.EmailField(blank=True, null=True, verbose_name="Email")
url = models.URLField(blank=True, null=True, verbose_name="URL") url = models.URLField(blank=True, null=True, verbose_name="URL")
happy_hour_start = models.TimeField(blank=True, null=True, verbose_name='Happy Hour Start')
happy_hour_end = models.TimeField(blank=True, null=True, verbose_name='Happy Hour Ende')
def __str__(self): def __str__(self):
return self.name return self.name