Update location model for happy hour
This commit is contained in:
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
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)
class LocationAdmin(admin.ModelAdmin):
list_display = ('code', 'name', 'city',)
fields = ['users', 'code', 'name', 'street', 'plz', 'city', 'phone', 'email', 'url', ]
form = LocationAdminForm
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)