Django modelformset is powerful!

I spent two days trying all kinds of non-sense trying to setup a form for entering the temperature profile steps. In the end, it turns out using modelformset is so easy! No need to setup extra form for each model. No need to keep tracking which form is initialized by which object.  Two lines take care of everything!

RecipeSet=modelformset_factory(Recipe,extra=7,max_num=8)
n=RecipeSet(queryset=Recipe.objects.all().order_by(‘step’))

Django rocks!

Advertisements

Don’t repeat yourself, unless with style.

Don’t repeat yourself (DRY)

Every distinct concept and/or piece of data should live in one, and only one, place. Redundancy is bad. Normalization is good.

The framework, within reason, should deduce as much as possible from as little as possible.

In most occasions, repeating is a waste of energy and resources. When we do need to repeat ourselves, we should repeat with style, like Pachelbel’s Canon.

%d bloggers like this: