from django.contrib import admin from .models import * 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 hh_start is not None and hh_end is not None and 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): 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) class ClientAdmin(admin.ModelAdmin): list_display = ('uuid', 'location', 'report_user') fields = ['location', 'uuid', 'report_user'] @admin.register(LocationData) class LocationDataAdmin(admin.ModelAdmin): list_display = ('client_id', 'desk_no', 'tst', 'on_off', 'processed', 'error_msg') fields = ['client_id', 'desk_no', 'tst', 'on_off', 'processed', 'error_msg'] class DeskAdminForm(forms.ModelForm): def clean_desk_no(self): id = self.instance.id client = self.cleaned_data['client'] desk_no = self.cleaned_data['desk_no'] t = Desk.objects.filter(desk_no=desk_no, client=client).exclude(id=id) if t.count() > 0: raise ValidationError('Tischnummer bereits vergeben.') return self.cleaned_data['desk_no'] @admin.register(Desk) class DeskAdmin(admin.ModelAdmin): form = DeskAdminForm list_display = ('client', 'desk_no', 'name', 'enabled', 'prize', 'prize_hh') @admin.register(Accounting) class AccountingAdmin(admin.ModelAdmin): list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed', 'account_user') list_filter = ('account_user', 'billed')