lundi 23 avril 2018

Django: How to update a IntegerField based on previous ChoiceField, but keep it editable?

I hava the following form:

class form1(forms.ModelForm):
    CHOICES = (('EASY', 'EASY'), ('MEDIUM', 'MEDIUM'), ('HARD', 'HARD'))
    dificulty = forms.ChoiceField(choices=CHOICES)
    xp = forms.IntegerField()

I want to change the xp field based on the dificulty field choice.

Like, if the user put EASY on dificulty, change xp to 30. But keeping it editable, so the user can specify if it will be 31 or 29, or something like that.




Aucun commentaire:

Enregistrer un commentaire