References
Category:1882 births
Category:1957 deaths
Category:People from Manche
Category:French classical composers
Category:French classical musicians
Category:French composers of classical music
Category:French male classical composers
Category:Conservatoire de Paris alumni
Category:Academics of the Conservatoire de Paris
Category:Academics of the École Normale de Musique de Paris
Category:20th-century classical composers
Category:French classical trumpet players
Category:Musicians from Normandy
Category:Burials at Père Lachaise Cemetery
Category:20th-century French composers
Category:20th-century French male musiciansQ:
Django form class: how to include code from another class
I have a code that validates data I save in db.
class User_Type_Form(forms.Form):
def validate(self, username):
# validate data in db
class User_Form(forms.Form):
username = forms.CharField(label='Username', required=True, widget=forms.TextInput())
I want to use this code in form User_Form. But I cannot pass User_Type_Form because it is empty when I pass it to User_Form. Is there a way I can make this code available in my User_Form class, that is when I pass it to User_Form it would check if User_Type_Form.validate is empty then run it. I'm a newbie so any help would be appreciated. Thanks.
A:
I would create a FormMixin which looks for the validate() method and runs it:
class FormMixin(object):
def validate(self):
# validate data in db
class User_Type_Form(FormMixin, forms.Form):
pass
class User_Form(forms.Form, FormMixin):
username = forms.CharField(label='Username', required=True, widget=forms.TextInput())
Headlines
Kotch to try to improve among NFL-ready Panthers
CHARLOTTE, N.C. - The Panthers are counting on Jake Kotch to make a difference ac619d1d87
Related links:
Comentarios