On May 14, 2008, at 5:28 PM, Brandon Taylor wrote:
>
> Hi everyone,
Hi :) Okay, let first begin by explaining some fundamental basics
about Django itself. The admin in trunk uses oldforms. To use custom
validation there you would write a validator that would go in
validator_list on the model field. That no longer works in newforms-
admin. The admin in newforms-admin uses newforms. Surprise! :) I would
highly recommend you read the newforms documentation [1] if you have
never used newforms before.
Here is a very quick way to do some custom validation (not specific to
your example, that is your exercise):
from django.db import models
from django import newforms as forms
from django.contrib import admin
class Person(models.Model):
name = models.CharField(max_length=100)
class PersonForm(forms.ModelForm):
class Meta:
model = Person
def clean_name(self):
value = self.cleaned_data["name"]
if name == "Brian":
raise forms.ValidationError, u"You are not allowed to be
named Brian."
return value
class PersonAdmin(admin.ModelAdmin):
form = PersonForm
admin.site.register(Person, PersonAdmin)
That is the code required, I haven't tested it, but it should work.
Clearly don't drop it into one file as it is best to split that code
out, but shown for ease of coding ;) Let me know if you have any
further questions.
Brian Rosner
http://oebfare.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---