Questions tagged [django-queryset]

Django querysets are the primary abstraction for retrieving objects from Django's ORM system

Django querysets are the primary abstraction for retrieving objects from Django's ORM system using custom SQL queries. They abstract both the creation of queries as well as the assembly of the model objects that are returned.

See also

6784 questions
2
votes
1 answer

Execution time difference between Django query and raw sql query in terminal

I have a Django query which running well but I the execution slower than I make this same query in terminal. In curiosity I have run the django query (i have read it from Django Debug Tooltbar) in terminal and I got the same slow query. I tried to…
user9322651
2
votes
1 answer

Django annotate queryset with intersection count

Djangonauts, I need to tap your brains. In a nutshell, I have the following three models: class Location(models.Model): name = models.CharField(max_length=100) class Profile(models.Model): locations_of_interest =…
creimers
  • 4,975
  • 4
  • 33
  • 55
2
votes
1 answer

Django complex query for OR

I'm using django 1.10 I've created this query which works for me: filters_qs = filters_qs.filter( Q( user__in=[cache.user for cache in caches], status_id__in=[Status.Open['id'], Status.Empty['id']], revision=0 ) | …
user2880391
  • 2,683
  • 7
  • 38
  • 77
2
votes
2 answers

How can I filter whether a list contains the param?

How can I filter whether a list contains the param? In my Django-Rest-Framework project, I list the physical_server: [ { "id": 23, "name": 'A1' "ipv4s": [ { "id": 313, "ip":…
qg_java_17137
  • 3,310
  • 10
  • 41
  • 84
2
votes
0 answers

Annotate non-model attribute in Django queryset

I have a model Event which has a ManyToManyField named users. I want to get all the events with an extra attribute which denotes whether a specific user belongs to this event or not. class Event(models.Model): users =…
SHIVAM JINDAL
  • 2,844
  • 1
  • 17
  • 34
2
votes
1 answer

How to use Django __time lookup in a queryset

I have a model with 2 datetime fields which looks like this: class Booking(models.Model): start_date = models.DateTimeField() end_date = models.DateTimeField() ... As test data I have 2 bookings with start_date before 17:30 and 2…
Jcraine
  • 23
  • 5
2
votes
3 answers

Django queryset of articles by authors the user is following

I have two models class Account(AbstractBaseUser, PermissionsMixin): followers = models.ManyToManyField( 'Account', related_name='followers', blank=True, ) following = models.ManyToManyField( 'Account',…
woe-dev.
  • 933
  • 1
  • 7
  • 12
2
votes
1 answer

django how to annotate to the count in select query values

Using django2.0.2 python3.4 drf skip details ex)meta,password,postcontent ... models.py class Userinfo(models.Model) usersuid = BigAutoField(db_column='UserUID', primary_key=True) username = models.CharField(db_column='UserName') class…
Adam
  • 325
  • 1
  • 4
  • 20
2
votes
2 answers

Why do Get and Filter give different results? (Django)

I am developing an app where students can evaluate their teachers. I have several models, but the important ones for this question are these: class Professor(models.Model): name = models.CharField(max_length=50,null=True) categories =…
ozo
  • 883
  • 1
  • 10
  • 18
2
votes
1 answer

Annotate Django queryset with previous Sunday based on row's date field

I have a table with a set of Orders that my customers made (purchased, to say so). The customers can choose the delivery date. That value is stored in each Order in a field called Order.delivery_date (not too much inventive there) class…
Savir
  • 17,568
  • 15
  • 82
  • 136
2
votes
3 answers

How to pass value from get_queryset() to get_context_data()

As get_queryset() returns only one queryset and I need the length of the queryset search_store to the template file. So, I'm trying to send the value to the template through get_context_data. I know I can get a length of a queryset through {{…
Jay P.
  • 2,420
  • 6
  • 36
  • 71
2
votes
3 answers

Django complex query to parent

I am using django and I am having a little trouble figuring out how to handle complex queries to the database. I have two models: Parent: id = models.AutoField(primary_key = True) name = models.CharField(max_length = 60) category =…
Adrian
  • 198
  • 4
  • 16
2
votes
2 answers

Django: get unique together fields and count how many times they appear in a table

I am trying to create a trip monitoring app whereas each trip is given a ticket and particular origin and destination. What I want to do now is that given a date range, I would like to know how many trips are made for the unique origin-destination…
Josh21
  • 506
  • 5
  • 15
2
votes
1 answer

all: unable to get repr for

I am using Python3.6 and django 2.0.2, and developing a website for user search in Pycharm. I want to use a legacy database which called User, and had data saved automatically from other source, I won't change the database during the website…
tina
  • 31
  • 1
  • 6
2
votes
1 answer

Django - Zip multiple querysets with uncommon fields data

I have this one model where I have fetch published count , under process count, rejected count, received count on monthly basis class PreData(models.Model): status=models.CharField(max_length=200,default=None,null=True) …
joelvarma
  • 150
  • 3
  • 17