Created
October 20, 2015 17:16
-
-
Save mekhami/5d82e29b1a7b094ef844 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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