django-q Questions
16
Solved
I'm trying to build the search for a Django site I am building, and in that search, I am searching across three different models. And to get pagination on the search result list, I would like to us...
Spaceless asked 10/1, 2009 at 19:51
2
Solved
I would like to perform a logical exclusive OR (XOR) on django.db.models.Q objects, using operator module to limit the choices of a model field to a subset of foreignkey. I am doing this in Django ...
Scuppernong asked 5/2, 2013 at 15:38
3
Is it possible to modify Django Q() objects after construction? I create a Q() object like so:
q = Q(foo=1)
is it possible to later change q to be the same as if I had constructed:
q2 = Q(foo=1...
Institute asked 3/9, 2014 at 14:13
1
I have a Django model where each instance requires a unique identifier that is derived from three fields:
class Example(Model):
type = CharField(blank=False, null=False) # either 'A' or 'B'
time...
Grunt asked 19/2, 2020 at 2:0
5
Solved
I'm trying to query a database based on user input tags. The number of tags can be from 0-5, so I need to create the query dynamically.
So I have a tag list, tag_list, and I want to query the data...
Crust asked 25/10, 2012 at 20:34
14
Solved
From an example you can see a multiple OR query filter:
Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3))
For example, this results in:
[<Article: Hello>, <Article: Goodbye>, <...
3
Solved
I have a complex Q object created dynamically. How do I negate the Q object so that it can be used in filter() instead of exclude()?
1
Solved
I'd like to use the django.db.models.Q object in a way that the query term is coming from a variable.
What i'd like to achieve is identical to this:
q = Q(some_field__icontains='sth')
Obj.objects.f...
1
Solved
I've got these models:
class Container(models.Model):
...
class Meta:
constraints = [
models.CheckConstraint(
check=~Q(elements=None),
name='container_must_have_elements'
),
]
class Eleme...
Adamec asked 11/2, 2020 at 16:48
3
Solved
Now I use just Q(id=0), and that depends on DB. Or maybe Q(pk__isnull=True) is better? It is useful for concatenation Q objects with using of | operator.
Tryst asked 1/7, 2015 at 12:13
4
Solved
I try to combine AND and OR in a filter using Q objects. It looks like that the | behave like an AND. This is related to the previous annotate which is run in the same query and not as a subquery.
...
6
Solved
I want to create some part of Django ORM filter query dinamicly, now I can do:
if some:
Obj.filter(
some_f1=some_v1,
f1=v1,
f2=v2,
f3=v3,
f4=v4,
...
)
else:
Obj.filter(
f1=v1,
f2=v2,
f...
Morten asked 4/11, 2015 at 8:55
2
I wonder which is the correct way to construct a Q(...) object which matches no object in the queryset. It seems that both Q() and ~Q() match all objects!
3
Solved
I have a Django QuerySet, and I want to get a Q object out of it. (i.e. that holds the exact same query as that queryset.)
Is that possible? And if so, how?
Freezedrying asked 14/3, 2012 at 14:6
3
Solved
I have a basic Django model like:
class Business(models.Model):
name = models.CharField(max_length=200, unique=True)
email = models.EmailField()
phone = models.CharField(max_length=40, blank=Tr...
3
Solved
g = Goal.objects.filter(Q(title__contains=term) | Q(desc__contains=term))
How can I add to my filter that user=request.user?
This doesn't work:
g = Goal.objects.filter(user=request.user, Q(titl...
4
Solved
I'm looking to create a slightly more complex query that is written fairly easily using raw SQL. Here's an example of the query in raw:
SELECT my,fields FROM sales WHERE is_paid = False OR statu...
2
I have a curious problem.
I have 3 objects. All the same
class Articles(models.Model):
owner = models.ForeignKey(Author)
tags = models.ManyToManyField('Tag')
class Tag(models.Model):
name = ...
1
I have the following 2 Django models:
from mptt.models import MPTTModel, TreeForeignKey
from django.db import models
from django.db.models import Q
class Model1(MPTTModel):
random_field = models...
Reversible asked 26/12, 2015 at 4:29
1
Solved
What is the difference between
queryset.filter(Q(foo='bar') | Q(foo='baz'))
and
queryset.filter(foo__in=['bar', 'baz'])
I'm finding that sometimes they produce different results and I can't f...
Aribold asked 2/10, 2015 at 9:18
1
So this is the scenario:
class Person(models.Model):
...
class Aktion(models.Model):
...
class Aktionsteilnahme(models.Model):
person = models.ForeignKey(Person)
aktion = models.ForeignKey(Ak...
Heddie asked 23/5, 2015 at 22:24
1
Solved
I have a Model:
class Authors(models.Model):
name = models.TextField()
person = models.ForeignKey(Person)
and query:
authors = Author.objects.filter(
(Q(name__iregex=r"\y{0}\y".format(s1))...
1
Solved
I have a form that allows you to pick multiple project types to filter from. For instance, say you have the project types "Research", "Training", and "Evaluation".
Basically what I'm looking to d...
Alphonso asked 26/11, 2013 at 16:22
2
Solved
First example:
# ANDing Q objects
q_object = Q()
q_object.add(Q(), Q.AND)
# ORing Q objects
q_object = Q()
q_object.add(Q(), Q.OR)
Second example:
>>> import operator
# create a...
Mendelsohn asked 19/2, 2013 at 12:32
2
Solved
I'm working with a query that looks like so:
filters = Q(is_default = False)
# Build the excludes and filters dynamically
if cut:
filters = filters & Q(mailbagstats__num_letters2__gt = in...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.