[Fixed]-Populating field options from a different field in Django

1đź‘Ť

I think you shouldn’t doing this at the database level. The relations between your models are fine, but the database doesn’t care what a “Litterature” category is or whatever. The architecture enforces the integrity of data architecture, i.e, a subcategory has only one category. Then, it’s up to you to enforce the integrity of content.

So for your specific problematic, I think you’re best bet is handling the form via Ajax. You could setup a form with the fields you want, and populate these fields via Ajax, on select callback from above field.

When user validates the form, it’s up to you to perform a custom validation (in the clean method of your form), testing the integrity of data and raising custom error if needed.

Let met know if you want a more detailed answer with form + view + js part.

Leave a comment