Created
April 13, 2020 01:04
-
-
Save TheoOliveira/2e9512dbf626ed35ff89ae2d8eca9fa9 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 .models import Product | |
| class ProductForm(forms.ModelForm): | |
| title = forms.CharField(label='Título') | |
| price = forms.IntegerField(label='Preço') | |
| summary = forms.CharField(label='Resumo', widget=forms.Textarea(attrs={'cols':15, 'rows': 2})) | |
| class Meta: | |
| model = Product | |
| fields = [ | |
| 'title', | |
| 'price', | |
| 'summary' | |
| ] | |
| def clean_title(self, *args, **kwargs): | |
| title = self.cleaned_data.get('title') | |
| if 'CFE' in title: | |
| return title | |
| else: | |
| raise forms.ValidationError('This is not valid') | |
| class RawProductForm(forms.Form): | |
| title = forms.CharField(label='Título') | |
| price = forms.IntegerField(label='Preço') | |
| summary = forms.CharField(label='Resumo', widget=forms.Textarea(attrs={'cols':15, 'rows': 2})) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment