Source

dvd-collection / collection / forms.py

from django import forms
from collection.models import Movie, Genre
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password

class MovieForm(forms.ModelForm):
    class Meta:
        model = Movie
        fields = ('title', 'year', 'format', 'genre', 'rating', 'purchase_price', 'market_price', 'imdb', 'youtube',)

class GenreForm(forms.ModelForm):
    class Meta:
        model = Genre
        fields = ('name',)

class UserForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput)
    password2 = forms.CharField(widget=forms.PasswordInput, label='Password again')
    class Meta:
        model = User
        fields = ('username', 'email', 'first_name', 'last_name', 'password',)
    def clean_password(self):
        data = self.cleaned_data['password']
        return data
    def clean_password2(self):
        data = self.cleaned_data['password2']
        if data != self.cleaned_data['password']:
            raise forms.ValidationError("The passwords you entered did not match.")
        return data