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
2 answers

What is the best way to keep track on tables or some data for analytics?

For an instance, take django model classes as below. So, now the question is that how can I efficiently implement analytics for generating number of product sales per day, number of sales per month, number of profit by day and so on ? One Possible…
Devang Padhiyar
  • 3,427
  • 2
  • 22
  • 42
2
votes
2 answers

Delete Django QuerySet objects with a duplicate value in a particular field

I have this Django model (from Django CMS): class Placeholder(models.Model): slot = models.CharField(_("slot"), max_length=50, db_index=True) default_width = models.PositiveSmallIntegerField(_("width"), null=True) I want to delete the…
coffee-grinder
  • 26,940
  • 19
  • 56
  • 82
2
votes
2 answers

How to speed up copy_expert in postgresql?

The following function imports around 60k records in 111 seconds. I've heard others say that copy_from and copy_expert are doing 1 million records in less than a minute. Is there something about using copy_expert that is slowing down process vs…
Casey
  • 2,611
  • 6
  • 34
  • 60
2
votes
2 answers

How can I speed up Django Query aggregations on a 10 million row database with 60 features?

I have a database table in psql which contains of 10,000,000 rows and 60 columns (features). I define a Django Queryset as follows: MyQ=MyDataBase.objects.filter(Name='Mike', date=date(2018, 2, 11), Class='03') There are only 5 rows that satisfy…
Mike
  • 369
  • 5
  • 21
2
votes
1 answer

Enrich Django QuerySet different outcomes

Goal Querying for all products, slicing them, returning subset of those products with an added key:value , in other words, enriched. Code that works but I can't use I can't use this code because I use a paginator, the paginator accesses the count…
Chayemor
  • 3,577
  • 4
  • 31
  • 54
2
votes
1 answer

Django Queryset many to many

I have an issue with the output of a ManyToMany query in Django I have two classes: Investor and Fund. A Fund can have many Investors, and an Investor can be invested in multiple Funds, hence the Manytomany relationship The objective is to show in…
TMD
  • 191
  • 1
  • 2
  • 14
2
votes
1 answer

Sum Product using Django ORM

I need to calculate the sumproduct of two fields from Django queryset. I have checked the answer in Django Aggregation: Summation of Multiplication of two fields but it doesnt work. They suggest the following code for django < 1.8: from…
Mike
  • 369
  • 5
  • 21
2
votes
5 answers

Django ORM: All users which have at least one group

I want to find all users which are at least in one group. I found a solution from django import setup setup() from django.contrib.auth.models import User user_without_group =…
guettli
  • 25,042
  • 81
  • 346
  • 663
2
votes
1 answer

Query which orders users by last message sent in Django Private Chat

I want to create a queryset which retrieve users efficiently ordered by the create date of the last Message they sent OR received (like most of the chat interfaces do). I am using Django Private Chat, which uses this simple model for messages. I…
2
votes
1 answer

Django ListView queryset for available items

So I want to display all available items for any given date, shouldn't be that hard but somehow I ran into a problem concerning related items. Let's say we have the following models, a model to store all bookings and a model with the Item. Then I…
Kevin D.
  • 315
  • 2
  • 19
2
votes
1 answer

How do I override the .update() method inside a custom manager class

How can I override the update() method of a django model inside a custom manager? I would like to modify the behavior of some methods(all(), update(), filter()) of a django model and I have tried to override using what my code down here suggests but…
Olfredos6
  • 808
  • 10
  • 19
2
votes
1 answer

Django sort inside groups of related to foreign key objects

I have a following model: class Mountain(models.Model): name = CharField(max_length=200) class Climbing(models.Model): mountain = models.ForeignKey(Mountain) climber = CharField(max_length=200) date =…
Alex Zaitsev
  • 690
  • 6
  • 17
2
votes
1 answer

Django Query: How to order posts by amount of upvotes?

I'm currently working on a website (with Django), where people can write a story, which can be upvoted by themselves or by other people. Here are the classes for Profile, Story and Upvote: class Profile(AbstractBaseUser, PermissionsMixin): email =…
2
votes
1 answer

How to check new posts since users last login Django

Intro: I have a 3 models user, post, group. User is able to make posts however each post has to belong to a group. Users have to choose from the existing groups for their posts. Users cannot add, delete, update group's. Furthermore: Users can become…
2
votes
1 answer

Why am I getting an UnorderedObjectList Warning even though I'm following a conventional usage of the order_by() function?

I have a generic list view from which I paginate using the querysets from two separate models : Message and safeTransaction. django terminal output gives this warning upon entry to my inbox view :…
timi95
  • 368
  • 6
  • 23