django-queryset Questions
4
I am trying to get display names of choices when using annotate, but I haven't been able to figure out. I have the following query:
Survey.objects.values('what').annotate(count=Count('why')).order...
Extravagancy asked 2/4, 2015 at 19:24
2
Solved
I want to optimize the django app and for this I would like to know How can I check if my query is hitting database or I am getting result/return value from cached version?
For example:
products = ...
Speculation asked 18/8, 2020 at 7:9
3
Solved
I have below query where I want to fetch 'specs' which is a dictionary but the type of envi_dict is a Queryset class. How do I fetch the dictionary from this queryset? Any help is much appreciated....
Mitran asked 5/12, 2017 at 7:25
7
Solved
Just came across this in the django docs
Calling none() will create a queryset that never returns any objects
and no query will be executed when accessing the results. A qs.none()
queryset is ...
Pustule asked 12/1, 2013 at 3:22
3
Solved
I have two models:
class Author(models.Model);
name = models.CharField(max_length=255)
class Book(models.Model):
title = models.CharField(max_length=255)
authors = models.ManyToManyField(Autho...
Diglot asked 27/8, 2012 at 10:5
5
Solved
I'm trying to optimize my ORM queries in django. I use connection.queries to view the queries that django generate for me.
Assuming I have these models:
class Book(models.Model):
name = models.C...
Apoplectic asked 20/10, 2015 at 7:29
4
Solved
Say I have a model:
Class Person(models.Model):
firstname = models.CharField()
lastname = models.CharField()
birthday = models.DateField()
# etc...
and say I have a list of 2 first names: fi...
Haggar asked 24/11, 2013 at 17:46
10
Solved
I have a model Employees and I would like to have a QuerySet of all rows, but with some specific fields from each row, and not all fields.
I know how to query all rows from the table/model:
Employe...
Groundage asked 21/9, 2011 at 16:26
6
Solved
In Django, what's the difference between the following two:
Article.objects.values_list('comment_id', flat=True).distinct()
versus:
Article.objects.values('comment_id').distinct()
My goal is to g...
Gladisgladney asked 13/5, 2016 at 9:7
10
I want to serialize my queryset, and I want it in a format as this view outputs:
class JSONListView(ListView):
queryset = Users.objects.all()
def get(self, request, *args, **kwargs):
return Htt...
Richardo asked 8/4, 2013 at 8:10
2
this is realted to my other question
django-rest-framework, multitable model inheritance, ModelSerializers and nested serializers
In django rest framework we can define nested model serializer lik...
Necrotomy asked 5/6, 2014 at 18:19
2
Solved
I have the following models
class Film(models.Model):
crew = models.ManyToManyField('Person', through='Role', blank=True)
class Role(models.Model):
person = models.ForeignKey('Person')
film = ...
Paperboy asked 29/1, 2016 at 20:10
5
Solved
I have a model something like this:
class Task(models.Model):
progress = models.PositiveIntegerField()
estimated_days = models.PositiveIntegerField()
Now I would like to do a calculation Sum(p...
Aleedis asked 28/8, 2012 at 18:54
5
Solved
I have a queryset(which is filtered actually) as below
posts = [<Post: published>, <Post: needs>, <Post: be>, <Post: issues>, <Post: to>, <Post: tags>]
But i ...
Fed asked 4/9, 2013 at 7:19
2
Solved
lets say I have a model Comments and another model Answers. I want to query all comments but also include in the query the number of answers each comment has. I thought annotate() would be useful i...
Sonia asked 26/10, 2015 at 21:41
5
Solved
I have a query that requires to filter exactly 2 authors with the ID
Theoretically,
Book.objects.filter(author__id=1, author__id=2).
which is not possible.
How can I solve this problem?
Che...
Limnology asked 14/3, 2011 at 17:16
21
I am trying to filter a DateTimeField comparing with a date. I mean:
MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22))
I get an empty queryset list as an answer because (I think) I...
Bathroom asked 23/8, 2009 at 3:52
3
Solved
I started investigating why my Django Model.objects.filter(condition = variable).order_by(textcolumn) queries do not yield objects in correct order. And found out that it is database (Postgresql) i...
Sapowith asked 21/9, 2013 at 17:51
5
Solved
model.py
class Tdzien(models.Model):
dziens = models.SmallIntegerField(primary_key=True, db_column='DZIENS')
dzienrok = models.SmallIntegerField(unique=True, db_column='ROK')
class Tnogahist(m...
Thimbleweed asked 25/10, 2013 at 12:54
2
Solved
I have a query akin to the following:
SELECT SUM(name) FROM table WHERE name IS NULL
How does that SUM translate into a QuerySet in Django? i.e. What operation xyz does it translate to, in somethi...
Assent asked 26/6, 2011 at 0:1
5
Using Django 1.8 on Python 3.4.1 with models:
class Product(models.Model):
name = models.CharField(max_length=255)
# some more fields here
def __str__(self):
return self.name
class PricedPr...
Instruction asked 15/4, 2015 at 10:8
2
Solved
I'm trying to sum a complete field after filtering objects using pk.
Views.py
def items(request, pk):
current_user = request.user
selected_itemz = get_object_or_404(ItemIn, pk=pk)
all_cats = C...
Inhibitory asked 13/5, 2018 at 12:51
6
Solved
I have these models:
def Foo(Models.model):
size = models.IntegerField()
# other fields
def is_active(self):
if check_condition:
return True
else:
return False
def Bar(Models.model):
foo...
Brittneybrittni asked 16/2, 2010 at 22:14
2
class Parent(models.Model):
# some fields
class Child(models.Model):
parent = models.ForeginKey(Parent)
species = models.ForeignKey(Species)
# other fields
I have a function like this:
1. def...
Voluntarism asked 31/7, 2020 at 7:53
3
Solved
I'm trying to do a django query, but with the possibility of several different WHERE parameters. So I was thinking of doing something like:
querystring = "subcat__id__in=[1,3,5]"
Listing.objects.f...
Sentiment asked 28/11, 2010 at 0:53
1 Next >
© 2022 - 2024 — McMap. All rights reserved.