Skip to content

Instantly share code, notes, and snippets.

@TheoOliveira
Created April 13, 2020 01:04
Show Gist options
  • Select an option

  • Save TheoOliveira/2e9512dbf626ed35ff89ae2d8eca9fa9 to your computer and use it in GitHub Desktop.

Select an option

Save TheoOliveira/2e9512dbf626ed35ff89ae2d8eca9fa9 to your computer and use it in GitHub Desktop.
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