Fix FarmSelect
Corrigido a forma como o sistema busca as informações de Animais e Piquetes para exibir na tela de seleção de Fazenda
This commit is contained in:
1 parent
edc0f2170f
commit
35620936ac
1 file changed
+11
-3
@@ -1,6 +1,6 @@
|
||||
from django.shortcuts import redirect
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.db.models import Count
|
||||
from django.db.models import Count, Q
|
||||
|
||||
from ..forms import UserLoginForm
|
||||
|
||||
@@ -48,8 +48,16 @@ def farm_select(request):
|
||||
|
||||
farms_query = request.user.farms.filter(is_active=True)
|
||||
farms_with_counts = farms_query.annotate(
|
||||
total_animals=Count('animals'),
|
||||
total_paddocks=Count('paddocks')
|
||||
total_animals=Count(
|
||||
'animals',
|
||||
filter=Q(animals__is_active=True),
|
||||
distinct=True
|
||||
),
|
||||
total_paddocks=Count(
|
||||
'paddocks',
|
||||
filter=Q(paddocks__is_active=True),
|
||||
distinct=True
|
||||
)
|
||||
)
|
||||
|
||||
context = {
|
||||
|
||||
Reference in new issue
Block a user