David,

for me, these two links did the trick:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin
http://docs.djangoproject.com/en/dev/ref/forms/validation/#ref-forms-validation

However, validation as described in the Django docs does not happen in
the model's save method; it happens in the admin form. Above links
explain how to tell the admin layer to use your form class which
provides its own validation method. So you could alter the second
database in the validation method and raise a ValidationError if it
fails.
For example:

models.py:
class MyModel(models.Model):
  [...]

class MyModelAdminForm(forms.ModelForm):
  class Meta:
    model = MyModel

  def clean(self):
    data = self.cleaned_data

    try:
      # alter other DB here

    if x > y:
      raise forms.ValidationError(_("X must not be greater than y!"))

    return data

admin.py:
class MyModelAdmin(admin.ModelAdmin):
  form = MyModelAdminForm


--~--~---------~--~----~------------~-------~--~----~
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