On Tue, Aug 18, 2009 at 1:23 PM, Marek Palatinus <ma...@palatinus.cz> wrote:
> > On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo<josh.r.ru...@gmail.com> > wrote: > > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus <ma...@palatinus.cz> > wrote: > >> > >> Hello, > >> > >> Im doing some validation in ModelAdmin.save_model(). I can cancel > >> operation (just dont call parent method), but I also need to show some > >> error message to user. Im able to call self.message_user() and show > >> INFO message, but how to send ERROR message and maybe show form back > >> and force user to correct inputs? > >> > >> I need validation on level of whole formset, not on field level, so I > >> cannot use some custom field to achieve that. > > > > What you want is to override the ModelAdmin.form with a custom form and > > handle the clean_xxx() methods there. Django form validation is done in > the > > form objects/classes. > > Create a ModelForm > > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then > set > > your ModelAdmin.form to your new ModelForm. > > > > Joshua, thanks a lot! > > to others: there also exists clean() which have available all fields > from form at one place. I often also place checks in the save of a model (like you were doing) to help catch scenarios when using the models in your own code (outside of the admin app). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---