samedi 23 juillet 2016

django - validate char field as email

Lets say i have model:

class Subscription(models.Model):
    address = models.CharField(max_length=255)

then i create form:

class SubscriptionForm(ModelForm):
    class Meta:
        model = Subscription
        fields = ['address']
    def clean_address(self):
        email = self.cleaned_data['address']
        #VALIDATE HERE IF IT IS EMAIL
        return email

How can i apply email validator to my field without changing model?

EDIT: Is this even possible?

Aucun commentaire:

Enregistrer un commentaire