[Answer]-Using formset to display and validate many-to-many relationships

1👍

Learn about formsets and modelformsets. You can use something like:

formset = modelformset_factory(Measurement)

Warning if there is a lot of recipes and ingredients, then rendering the select for ingredient and recipe for each form will be slow. A simple solution is to use an autocomplete app.

Example with django-autocomplete-light:

autocomplete_light.register(Ingredient, search_fields=['title'])
autocomplete_light.register(Recipe)

formset = modelformset_factory(Measurement, 
    form=autocomplete_light.modelform_factory(Measurement))
👤jpic

Leave a comment