from django.forms import ModelForm
from models import Sandwich, Ingredient
from django.contrib.auth.models import User
+from django import forms
class SandwichForm(ModelForm):
class Meta:
model = Sandwich
- exclude = ('slug',)
+ exclude = ('slug', 'user', 'ingredients')
+ fields = ('adjective', 'date_made', 'notes', 'picture')
class IngredientForm(ModelForm):
exclude = ('slug',)
-class UserLoginForm(ModelForm):
-
- class Meta:
- model = User
- fields = ('username', 'password')
-
-class NewAccountForm(ModelForm):
-
- class Meta:
- model = User
- fields = ('username', 'first_name', 'last_name', 'email', 'password')
-
\ No newline at end of file
+class NewUserForm(forms.Form):
+ first_name = forms.CharField()
+ last_name = forms.CharField()
+ email = forms.EmailField()
+ username = forms.CharField()
+ password = forms.CharField(widget=forms.PasswordInput)
+ confirmpassword = forms.CharField(label=("Confirm password"), widget=forms.PasswordInput)
+
+ def clean_confirmpassword(self):
+ password = self.cleaned_data.get("password", "")
+ cpassword = self.cleaned_data["confirmpassword"]
+ if password != cpassword:
+ raise forms.ValidationError(("The two password fields didn't match."))
+ return cpassword