[Fixed]-Changing queryset on a ModelChoiceField

1πŸ‘

βœ…

I think the problem is that django ModelChoiceField uses the queryset to store all possible choices. If you change your front end code to pass in an id that isn’t in the queryset, django would fail your validation.

An easy solution would be to just use Label.objects.all() as the queryset for ModelChoiceField, but change the front end based on what the other choice is. If you concern about security, you can write your own validation to double check on the correlation between trans_type and model.

πŸ‘€Shang Wang

Leave a comment