Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
How to show/hide field in django admin with js?

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();
        }
    });
})
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!