Created
November 15, 2012 11:53
-
-
Save magopian/4078269 to your computer and use it in GitHub Desktop.
Reuse the Django admin's javascript (example with prepopulated_fields.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="{% static "admin/js/jquery.js" %}"></script> | |
<script src="{% static "admin/js/jquery.init.js" %}"></script> | |
<script src="{% static "admin/js/urlify.js" %}"></script> | |
<script src="{% static "admin/js/prepopulate.js" %}"></script> | |
<script> | |
// adaptation from django/contrib/admin/templates/admin/prepopulated_fields_js.html | |
(function($) { | |
var field = { | |
id: '#{{ form.###DESTINATION FIELD NAME###.auto_id }}', | |
dependency_ids: ['#{{ form.###SOURCE FIELD NAME###.auto_id }}'], | |
dependency_list: ['{{ form.###SOURCE FIELD NAME###.name }}'], | |
maxLength: {{ form.###DESTINATION FIELD NAME###.field.max_length|default_if_none:"50"|unlocalize }} | |
}; | |
$('.field-{{ form.###DESTINATION FIELD NAME###.name }}').addClass('prepopulated_field'); | |
$(field.id).data('dependency_list', field['dependency_list']) | |
.prepopulate(field['dependency_ids'], field.maxLength); | |
})(django.jQuery); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@romain-dartigues , I am also facing the similar problem after upgrading to django 3.2, my admin pagination is not working.