Custom Query (26909 matches)

Filters
 
Or
 
  
 
Columns

Show under each result:


Results (1 - 3 of 26909)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#11293 fixed Filters on aggregates lose connector - django@…
Description

When adding a filter on an aggregated column, it must be moved to the having clause instead of the where clause, but it loses the connector. Using the model in the Aggregation help topic:

>>> print Book.objects.values('publisher').annotate(pub_books=Count('id')).filter(Q(pub_books__gt=10) | Q(pub_books=1)).query.as_sql()
('SELECT `having_test_book`.`publisher_id`, COUNT(`having_test_book`.`id`) AS `pub_books` FROM `having_test_book` GROUP BY `having_test_book`.`publisher_id` HAVING (COUNT(`having_test_book`.`id`) > %s  AND COUNT(`having_test_book`.`id`) = %s ) ORDER BY NULL', (10, 1))

The HAVING clause should be an OR, not an AND. I think this happens because django.db.models.sql.query add_filter treats each filter individually.

A more complicated case that also needs to be handled is a filter that involves OR connectors as well as mixed aggregate and non-aggregate columns:

>>> print Book.objects.values('publisher').annotate(pub_books=Count('id')).filter(Q(pub_books__gt=10) | Q(pages=1)).query.as_sql()
('SELECT `having_test_book`.`publisher_id`, COUNT(`having_test_book`.`id`) AS `pub_books` FROM `having_test_book` WHERE `having_test_book`.`pages` = %s  GROUP BY `having_test_book`.`publisher_id` HAVING COUNT(`having_test_book`.`id`) > %s  ORDER BY NULL', (1, 10))

One filter ends up in WHERE, and the other in HAVING, but both need to be moved to HAVING for the connector to work.

#10104 duplicate Downloadable Documentation for Offline Reading (PDF, CHM, HTML) 1.0.2 vl4dt
Description

Online documentation is nicely formatted, grouped and styled and it would be nice to have it for offline reading as it would be easier to read and navigate through it.

#24911 fixed QuerySet is initiated with model=None as kwarg, but is called in BaseManager.get_queryset() as arg. Jonas Degrave Jonas Degrave
Description

QuerySet is initiated with model=None as named argument a.k.a. kwarg:

class QuerySet(object):
     def __init__(self, model=None, query=None, using=None, hints=None):

But it is called in get_queryset() as positional argument a.k.a. arg:

def get_queryset(self):
        return self._queryset_class(self.model, using=self._db, hints=self._hints)

This causes trouble when overriding get_queryset (which is the idea behind the method) and using super(BlaBlaManager, self).get_queryset() which returns a non-standard queryset-class, where model is not necessarily the first argument, which should have been okay as model is a named argument.

Proposed solution: in db/models/manager.py

def get_queryset(self):
        return self._queryset_class(model=self.model, using=self._db, hints=self._hints)

Github pull request: https://github.com/django/django/pull/4745

1 2 3 4 5 6 7 8 9 10 11
Note: See TracQuery for help on using queries.
Back to Top