python - how to pass a foreignkey attribute from django admin change_form.html to a javascript -
python - how to pass a foreignkey attribute from django admin change_form.html to a javascript -
consider models class definition: in models.py,
class classroom(models.model): subject1 = models.charfield(max_length=80) subject2 = models.charfield(max_length=80) class student(models.model): name = models.charfield(max_length=80) classroom = models.foreignkey(classroom)
i inheriting django's admin change_form.html template pupil model. need access subject1 , subject2 attributes can {{ adminform.form.instance.classroom.subject1 }} , same subject2. how access these values in javascript of form? based on value want hide/show value. don't want utilize custom view/template this, pass context variables. can achieved?
your template can contain javascript code html. set (js) variable value of template variable
<script...> myjsvar = "{{ mydjangovar }}" </script>
python django
Comments
Post a Comment