Changes between Version 45 and Version 46 of NewformsHOWTO


Ignore:
Timestamp:
08/13/2008 03:05:33 PM (7 years ago)
Author:
jarrow
Comment:

Fixed usage of the form attribute on ModelAdmin subclasses

Legend:

Unmodified
Added
Removed
Modified
  • NewformsHOWTO

    v45 v46  
    522522== Q: How do I add custom validation? ==
    523523
    524 One option is to override ```get_form()``` in your ```ModelAdmin``` subclass and provide a custom form that does the validation.  Alternatively, note that ```get_form()``` uses the class defined in the ```.form``` attribute of your ```ModelAdmin``` subclass, which by default is ``models.[http://www.djangoproject.com/documentation/modelforms/ ModelForm]``.  You can subclass this class and use it as below:
     524One option is to set the ```.form``` attribute of your ```ModelAdmin``` subclass to a subclass of [http://www.djangoproject.com/documentation/modelforms/ ModelForm] customized to your Model. Then override ```clean()```.
    525525
    526526{{{
     
    528528from django import forms
    529529from django.contrib import admin
     530form myproject.myapp.models import MyModel
    530531
    531532class MyModelForm(forms.ModelForm):
     533    class Meta:
     534        model = MyModel
    532535    def clean(self):
    533536        pass # Your custom validation here
Back to Top