check for duplicated desk_no
This commit is contained in:
parent
e74fc9d626
commit
0b1c7675f0
@ -1,5 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from .models import *
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
@admin.register(Location)
|
||||
@ -20,8 +22,21 @@ class LocationDataAdmin(admin.ModelAdmin):
|
||||
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.instance.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')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user