check for duplicated desk_no
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
				
			|||||||
from django.contrib import admin
 | 
					from django.contrib import admin
 | 
				
			||||||
from .models import *
 | 
					from .models import *
 | 
				
			||||||
 | 
					from django import forms
 | 
				
			||||||
 | 
					from django.core.exceptions import ValidationError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@admin.register(Location)
 | 
					@admin.register(Location)
 | 
				
			||||||
@@ -20,8 +22,21 @@ class LocationDataAdmin(admin.ModelAdmin):
 | 
				
			|||||||
    fields = ['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.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)
 | 
					@admin.register(Desk)
 | 
				
			||||||
class DeskAdmin(admin.ModelAdmin):
 | 
					class DeskAdmin(admin.ModelAdmin):
 | 
				
			||||||
 | 
					    form = DeskAdminForm
 | 
				
			||||||
    list_display = ('client', 'desk_no', 'name', 'enabled', 'prize', 'prize_hh')
 | 
					    list_display = ('client', 'desk_no', 'name', 'enabled', 'prize', 'prize_hh')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user