1π
β
I wonder if the data model here couldnβt use some tweaking? You might want to have a supply table with twenty rows and an intermediate table connecting them (that is a ManytoMany(Supply) or something like that). Then you could just have a multi select field, rather than 20 check boxes (unless you really need them for some other reason).
If you need to add another supply, itβs simply adding another row, rather than a schema migration.
π€James R
1π
supplies = Supply.objects.filter( supply1 = 1 )
And if you want to filter again:
supplies = supplies.filter(supply2 = 1)
The filter() method returns a QuerySet, so you can chain as many filter() calls as you like.
π€Matei Florescu
- [Answered ]-How do I optimize the following Django model queries?
- [Answered ]-Django-tables2: "Invalid block tag: 'query string' "
- [Answered ]-Django-How to deny access to a logged user directly to a specific URL
Source:stackexchange.com