dimanche 20 septembre 2020

Creating if statment in Django Crispy Forms, conditional form layout

I am using Django Cripsy Forms. I want to write if else statement, when the value of field name is "Daisy" Age field should appears, otherwise there should not be field 'age".

My code:

def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
      
     self.helper.layout = Layout(

         HTML(form_opening.format('Cats')),
         'name',
         'age',
          HTML(form_closing),
         
     ),
    ```

Aucun commentaire:

Enregistrer un commentaire