Minh-Hung Nguyen
Minh-Hung Nguyen

Reputation: 1254

Django admin on change event

I am using Django 1.7 and have a model admin with 2 textboxes. How can I listen to onchange event on the first one and update the second one?

Upvotes: 5

Views: 2813

Answers (1)

doniyor
doniyor

Reputation: 37856

define a form in admin.py

class YourForm(forms.ModelForm):
   class Media:
       js = ('//code.jquery.com/jquery-1.11.0.min.js', 'js/custom_admin_validate.js')

class YourAdmin(admin.ModelAdmin):
   form = YourForm
   #..

and now, in custom_admin_validate.js you can play with jquery in your adminpage.

please note, you may also want clean method of form to validate further in backend..

Upvotes: 4

Related Questions