Source code for core.forms
from django import forms
from django.core.exceptions import ValidationError
from django.contrib.auth.forms import UserCreationForm
from core.models import User,Image,Location
[docs]
class Add_Location_Form(forms.ModelForm):
[docs]
def clean(self):
cleaned_data = super().clean()
t=cleaned_data.get("type")
n=cleaned_data.get("name")
a=cleaned_data.get("account")
location_check = Location.objects.filter(type=t,name=n,account=a)
if location_check:
# Location records exist with this name - raise error
msg="A location for this type, with this name already exists - please use another location name"
self.add_error("name",msg)