In the clean() of an admin form I want to give the user some warnings.
So this is what I do in the admin -

class SomeForm(forms.ModelForm):
    class Meta:
        model = SomeModel

    def clean(self):
        self.warnings = []

        self.warnings.append("Warning: you seem to be confused.")

        return self.cleaned_data    


class SomeModelAdmin(admin.ModelAdmin):
    form = SomeForm
    
    def response_change(self, request, obj):
        for warning in SomeForm.warnings:
            messages.warning(request, warning)
            
        return super(SomeModelAdmin, self).response_change(request, obj)

Is that the correct way to do it? It works, but is that how it is
supposed to be done?

Thanks,

Daniele

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to