I have two models:
class Status(models.Model):
CHOISES = (
('new', 'New'),
('in_progress', 'InProgress'),
('on_review', 'OnReview'),
('tested', 'Tested'),
('delivered', 'Delivered')
)
status_type = models.CharField(
max_length=11,
choices=CHOISES,
primary_key=True)
class Task(models.Model):
name = models.CharField(max_length=200, blank=False)
status = models.ForeignKey(status)
part of my view:
def task_list(request):
all_tasks = Task.objects.all()
tasks = {}
tasks['new'] = all_tasks.filter(status_id='new')
tasks['in_progress'] = all_tasks.filter(status_id='in_progress')
tasks['on_review'] = all_tasks.filter(status_id='on_review')
tasks['tested'] = all_tasks.filter(status_id='tested')
tasks['delivered'] = all_tasks.filter(status_id='delivered')
....
part of my template:
{% for item in new %}
<div id="{{ item.pk }}">
{{ item.name }}
</div>
{% endfor %}
</div>
{% for item in in_progress %}
<div id="{{ item.pk }}">
{{ item.name }}
</div>
{% endfor %}
.....
The question is, is there any way to optimize all my querysets, or it is imposible to select five filters for one db call?
Like I understand, if I save in view only this call all_tasks = Task.objects.all() and then put logic in template, like this:
{% for item in all_task %}
{% if item.status_id == "new" %}
....
it will be exaclty five calls too
Hope my question is not too broad