models.py
from django.db import models
from django.contrib.auth.models import UserSTATUS_CHOICES = ((1, 'Accepted'),(0, 'Rejected'),)
class Leave(models.Model):----------------status = models.IntegerField(choices=STATUS_CHOICES, default = 0)reason_reject = models.CharField(('reason for rejection'),max_length=50, blank=True)def __str__(self):return self.name
admin.py
from django.contrib import admin
from .models import Leave@admin.register(Leave)
class LeaveAdmin(admin.ModelAdmin):-----------------class Media:js = ('/static/admin/js/admin.js')
- admin.js
(function($) {$(function() {var reject = document.getElementById('id_status_0')var accept = document.getElementById("id_status_1")var reason_reject = document.getElementById("id_reason_reject")if (accept.checked == true){reason_reject.style.display = "none"}else{reason_reject.style.display = "block"}});
})(django.jQuery);
Now I have imported the file in the admin.py, How do I trigger the jQuery function such that it works.
update-
the function works but, I need to reload the page to make the field appear and disappear. I want some thing equivalent to 'on-click'
event in HTML. I have no idea about Javascript.