I want to hide/show the field depending on the selection, but it doesn't work for me I have models:
STATUS_CHOICES = ((1, 'Accepted'),(0, 'Rejected'),)
class City(models.Model):
id = models.BigAutoField(primary_key=True)
status = models.IntegerField(choices=STATUS_CHOICES, default = 0)
name = models.CharField(max_length=200)
In my admin, i have:
@admin.register(City)
class CityAdmin(admin.ModelAdmin):
list_display = (
'pk',
'name',
'status',
)
form = CityForm
class CityForm(forms.ModelForm):
class Media:
js = ('targets-show.js',)
In targets-show.js
$(function() {
$('input[name="status"]').on('click', function() {
if ($(this).val() == '0') {
$('#id_name').show();
}
else {
$('#id_name').hide();
}
});
})