Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
How to read radio button value and use it from FORM in view.py file

This is the code that's in the

<fieldset class="form-group">
            <div class="row">
              <div class="col-sm-10">
                <div class="form-check form-check-inline">
                  <input class="form-check-input" type="radio" name="transaction" id="deposit" value="deposit" checked="checked">
                  <label class="form-check-label" for="deposit">
                    Deposit
                  </label>
                </div>
                <div class="form-check form-check-inline">
                  <input class="form-check-input" type="radio" name="transaction" id="deduction" value="deduction">
                  <label class="form-check-label" for="deduction">
                    Deduction
                  </label>
                </div>
              </div>
            </div>
          </fieldset>

I'm trying to take the 'transaction' and use it view.py and the calculations would be something like this in view.py:

        def form_valid(self, form):
            if (#deposit is checked):
                newFinanceTotal = currentUserTotal + value
            else: 
                newFinanceTotal = currentUserTotal - value
            form.save()
            return super().form_valid(form)

And this is what I have in models.py:

class Finance(models.Model):

    FINANCE_CHOICES = (
        ('DP', 'Deposit'),
        ('DD', 'Deduction'),
    )
    transaction = models.CharField(max_length=2, choices=FINANCE_CHOICES,)transaction = models.CharField(max_length=2, choices=FINANCE_CHOICES,)

forms.py:

class FinanceForm(forms.ModelForm):
     
   class Meta:
       model = Finance
       fields = ('entryName', 'entryDate', 'transaction', 'value')
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda