0

This is my code:

class HighschoolForm(forms.ModelForm):

    class Meta:
        model = Highschool
        fields = ['id', 'dni', 'name', 'address', 'city', 'country', 'phone', 'mobile', 'mail', 'website', 'contact', 'entrydate']

    def clean_mail(self):
        mail = self.cleaned_data.get('mail')   #self.cleaned_data['mail']
        mail_base, proveedor = mail.split('@')
        dominio, extension = proveedor.split('.')
        if extension == 'ptn':
            raise forms.ValidationError('Does not allow Pluton mails....')
        return self.cleaned_data['mail']

However when I introduced data in ModelForm in the admin view a mail with a "ptn" extension, Django doesn't refused the data and record in the database. Which is the problem? I read de Django 2.0 documentation and I don't find the failure. Thanks

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
JuanC
  • 1
  • 2
  • 2
    Are you using this form in the admin? How? Show your ModelAdmin class. – Daniel Roseman Dec 28 '17 at 19:13
  • Yes, I use the form in admin. – JuanC Dec 29 '17 at 21:16
  • from django.contrib import admin from .models import Highschool from .forms import HighschoolForm class AdminHighschool(admin.ModelAdmin): list_display = ['id', 'dni', 'name', 'address', 'city', 'country', 'phone', 'mobile', 'mail', 'website', 'contact', 'entrydate',] formhs = HighschoolForm list_display_links = ['id', 'dni', 'name'] list_editable = ['address', 'phone', 'mobile', 'mail', 'website', 'contact'] list_filter = ['city','country'] search_fields = ['name'] admin.site.register(Highschool, AdminHighschool) – JuanC Dec 29 '17 at 21:26
  • You should have put that as an edit to the question. Why are you setting `formhs`? You need to set `form`. – Daniel Roseman Dec 29 '17 at 21:30

0 Answers0