[Python] Adding a jQuery script to the Django admin interface

Discussão em 'Python' iniciado por Stack, Fevereiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm gonna slightly simplify the situation. Let's say I've got a model called Lab.

    from django.db import models

    class Lab(models.Model):
    acronym = models.CharField(max_length=20)
    query = models.TextField()


    The field query is nearly always the same as the field acronym. Thus, I'd like the query field to be automatically filled in after entering text in the acronym field in the Django admin interface. This task must be performed by a jQuery script.

    So if I take an example: you want to add a new lab to the database through the Django admin interface. You click the add button and you land on the empty form with the two fields. You manually fill in the acronym field with a value such as ABCD and then the query field should antomatically be completed with the same value, that means ABCD.

    How should I proceed?

    Continue reading...

Compartilhe esta Página