Filter queryset by group

0

I have a model called ColaNotificaciones.

class ColaNotificaciones(models.Model):
    class Meta:
        unique_together = (('remitente', 'destinatario', 'asunto','producto'),)

    remitente = models.CharField(max_length=20)
    destinatario = models.CharField(max_length=20)
    asunto = models.CharField(max_length=2)
    is_email = models.BooleanField(default=False)
    is_notificacion = models.BooleanField(default = False)
    f_publi = models.DateTimeField(auto_now_add = True)
    producto = models.IntegerField(default = None)

From this filter model, whatever is_email = False.

Once I get the queryset I want to filter again by product, to get a new queryset in which all the notifications of the same product come out, to generate an email in which you know how many notifications you have and which senders have notified.

    
asked by F Delgado 12.02.2018 в 11:50
source

2 answers

1

what I'm going to plait here will return a list with notifications by product and another with the number of notifications per sender

not_por_producto = ColaNotificaciones.objects.filter(is_email=False).values('producto').annotate(contador=Count('producto'))

that query will return the number of notifications that there are per product

and in the same way for number of notifications per sender

not_por_remitente = ColaNotificaciones.objects.filter(is_email=False).values('remitente').annotate(contador=Count('remitente'))

This is the link to the documentation

    
answered by 02.03.2018 / 08:58
source
0

You can make both filters in the same queryset:

mi_filtro = ColaNotificaciones.objects.filter(is_email = False, product='Numero del producto que necesitas filtrar sin comillas')

You confirm if it works for you

    
answered by 12.02.2018 в 16:37