Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 691
Minh-Hung Nguyen Avatar asked Sep 29 '22 09:09

Minh-Hung Nguyen


1 Answers

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

like image 164
doniyor Avatar answered Oct 04 '22 04:10

doniyor