Hello I should like to do personalised validation in Django administration but I have always the same error : type object 'MainForm' has no attribute '_meta'
To do so, I use the following admin.py (attached file) Thanks in advance to anybody who could me unblocked. Serge Alard -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f66565b5-993e-4d89-b578-fcb1c605a416n%40googlegroups.com.
''' Superuser = admin password = idem à BD ''' from django.contrib import admin from django.forms import BaseModelForm, BaseInlineFormSet from .models import * from django.core.exceptions import ValidationError class MainInlineForm(BaseModelForm): model = Main fields = ('numero', 'pique', 'coeur', 'carreau', 'trefle') class MainInlineFormSet(BaseInlineFormSet): def carte_doublon(self, cartes): if cartes is None: return cartes l = [] for c in cartes: v = valeur_carte(c) l.append((v, c)) l = sorted(l, reverse=True) s = '' for (v, c) in l: s += c sd = '' c0 = None for c in s: if c == c0: sd += c c0 = c return sd def clean(self): if self.errors: return pique = '' for form in self.forms: pique += form.cleaned_data.get('pique') doublons = self.carte_doublon(pique) if len(doublons) > 1: raise ValidationError("'{}' de pique sont en double dans les différentes mains de la donne". format(doublons)) elif len(doublons) == 1: raise ValidationError("'{}' de pique est en double dans les différentes mains de la donne". format(doublons)) class MainInline(admin.StackedInline): model = Main fields = ('numero', 'pique', 'coeur', 'carreau', 'trefle') extra = 2 max_num = 4 form = MainInlineForm formset = MainInlineFormSet class DonneAdmin(admin.ModelAdmin): exclude = ('nb_aleatoire', 'numero') list_filter = ('chapitre',) inlines = (MainInline,) class MainAdmin(admin.ModelAdmin): exclude = ('pointsh',) ordering = ('numero',) def valeur_carte(c): if c == 'A': v = 14 elif c == 'R': v = 13 elif c == 'D': v = 12 elif c == 'V': v = 11 elif c == 'X': v = 10 else: v = ord(c) - 48 return v admin.site.register(Donne, DonneAdmin) admin.site.register(Main, MainAdmin)