Skip to content

Instantly share code, notes, and snippets.

@mekhami
Created October 20, 2015 17:16
Show Gist options
  • Select an option

  • Save mekhami/5d82e29b1a7b094ef844 to your computer and use it in GitHub Desktop.

Select an option

Save mekhami/5d82e29b1a7b094ef844 to your computer and use it in GitHub Desktop.
from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.forms.models import modelformset_factory
from .models import Invitee, Extra
class RSVPForm(forms.Form):
code = forms.CharField(max_length=56)
def clean(self):
cleaned_data = super().clean()
code = cleaned_data.get('code')
try:
person = Invitee.objects.get(code=code)
except ObjectDoesNotExist:
raise forms.ValidationError(
"Your code didn't match any records. Please "
"make sure you've typed it correctly, or "
"contact us if you feel there's an error."
)
return cleaned_data
class ExtraForm(forms.ModelForm):
class Meta:
model = Extra
fields = ('name',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment