How to show additional options after filling a Selection box in Django Admin

Asked

Viewed 13 times

0

When trying to register in Django Admin I have three fields to fill out being them tipo_remuneracao valor and valor_max, however depending on the type of compensation I may need to show value and max value or not. Ex: When selecting Combining in tipo_remuneracao I would like the valorand valor max disappear. I saw several issues in the stack overflow that solved the problea but it was necessary to reload the page, I do not want to have to reload. Below a screenshot of the fields:

inserir a descrição da imagem aqui

Model code:

class Remuneracao(models.Model):
    FAIXA_SALARIAL = 'FS'
    SALARIO_INICIAL = 'SI'
    SALARIO_EXATO = 'SE'
    A_COMBINAR = 'AC'
    TIPO_CHOICE = [
        (FAIXA_SALARIAL, 'Faixa Salarial'),
        (SALARIO_INICIAL, 'Salário Inicial'),
        (SALARIO_EXATO, 'Salário Exato'),
        (A_COMBINAR, 'A combinar'),
    ]

    HORA = 'HR'
    DIA = 'DI'
    SEMANA = 'SE'
    MES = 'ME'
    ANO = 'AN'
    TIPO_TEMPO_CHOICES = [
        (HORA, 'Hora'),
        (DIA, 'Dia'),
        (SEMANA, 'Semana'),
        (MES, 'Mês'),
        (ANO, 'Ano'),
    ]

    tipo = models.CharField('Tipo de remuneração', choices=TIPO_CHOICE, max_length=2)
    valor = models.DecimalField('Valor', decimal_places=2, max_digits=12)
    valor_max = models.DecimalField('Valor máximo', decimal_places=2, max_digits=12)
    tipo_tempo = models.CharField('Remuneração por', choices=TIPO_TEMPO_CHOICES, max_length=2, default=MES)
    vaga = models.OneToOneField(Vaga, on_delete=models.CASCADE)

admin code of that model:

@admin.register(Remuneracao)
class RemuneracaoAdmin(admin.ModelAdmin):
    list_display = ('tipo', 'valor', 'valor_max', 'tipo_tempo', 'vaga')

Thanks in advance.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.