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 RegisterForm(UserCreationForm):
[docs] class Meta: model = User fields = ["username", "email","password1", "password2"]
[docs] class UploadImageForm(forms.ModelForm):
[docs] class Meta: model = Image fields = ('name','image')
[docs] class Add_Location_Form(forms.ModelForm):
[docs] class Meta: model = Location fields = ['type','name']
[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)