Skip to main content

All Questions

0 votes
1 answer
23 views

How to sort values of a query in Django based on the quantity of child table?

I have a Product class that has a child class ProductColors. These are my two classes: class Product(models.Model): category = models.ForeignKey(Category, related_name='products', on_delete=models....
Pourya Mohamadi's user avatar
0 votes
1 answer
58 views

Django ORM efficient way for annotating True on first occurrences of field

I have a situation where we have some logic that sorts a patient_journey queryset (table) by some heuristics. A patient_journey has a FK to a patient. I now need an efficient way of setting True for ...
Octavio del Ser's user avatar
2 votes
1 answer
94 views

How to LEFT OUTER JOIN without foreign key using django orm

I have following Models: class User(Model): ### user fields ### class CaseModel(Model): id = # django build in id field owner = models.ForeignKey('User') ### other ...
Kholdarbekov's user avatar
  • 1,150
1 vote
1 answer
56 views

Django ORM model default not applying in python queryset

I have the below Django ORM which represents a PostgreSQL view. For the field cost_requirement I have set the default value to 0. However the queryset object still populates with None if data is ...
Andy's user avatar
  • 1,070
0 votes
1 answer
66 views

Django Postgresql ORM optimisation

I have a PostgreSQL view called view_sales_dashboard - this consists of several millions rows of daily sales data. In the Django view I want to present a table grouped by the products, with the ...
Andy's user avatar
  • 1,070
2 votes
1 answer
42 views

What is the fastest way to query for items with an existing foreign key and many-to-many entry in Django?

I have a simple model with a foreign key and a many-to-many relationship: class Car(models.Model): uuid = models.UUIDField() is_red = models.BooleanField() class Owner(models.Model): car =...
tommueller's user avatar
  • 2,506
0 votes
0 answers
59 views

FilteredRelation with OuterRef not working after updating to Django 5

After updating to Django 5, I have the same problem described in this post: How to use FilteredRelation with OuterRef? My queryset looks as follows: ModelA.objects.annotate( model_b_objects_count=...
Kathrin Wende's user avatar
0 votes
0 answers
56 views

Create and save() methods of the ORM of Django not working and is blocked

I have an app created with docker, that use a container with django, a frontend with Vue.js and a database with Postgres. The problem is, when I execute a query with create() or save(), it blocked the ...
Miguel Herreros's user avatar
1 vote
1 answer
53 views

How to add a duplicate column to a table?

I am retrieving data from the database using Django ORM: ws = Ws.objects.all() ws = ws.filter(*q_objects, **filter_kwargs) ws = ws.order_by(*sort_list) ws = ws.annotate(created_unix=UnixTimestamp(F('...
Victor's user avatar
  • 37
1 vote
1 answer
27 views

Can I declare two ForeignKey to the same table in one Django ORM abstract model?

Can you tell me if I can declare two ForeignKey to the same table in the same abstract model? I can do: class TrackableDateModel(models.Model): """Abstract model to Track the ...
Victor's user avatar
  • 37
0 votes
0 answers
32 views

Annotations returning pure PK value instead of Django HashID

In my application the user can assume one of 3 different roles. These users can be assigned to programs, and they can be assigned to 3 different fields, each of those exclusevely to a role. In my API ...
andrepz's user avatar
  • 481
1 vote
1 answer
49 views

What is Django ORM equivalent for sql "field <> 1"?

Assuming that field is nullable, in raw SQL condition WHERE field <> 1 will exclude all 1 rows and also exclude all NULL rows. Why Django ~Q(field=1) makes query WHERE (NOT (field = 1 AND field ...
masb's user avatar
  • 23
1 vote
2 answers
146 views

`UNIQUE constraint failed at: pharmcare_patient.id` in my pharmcare app

I have a Django app in my project I am currently working on called pharmcare, and I kind of getting into a unique constraint issue whenever I want to override the save() method to insert/save the ...
Blaisemart's user avatar
0 votes
0 answers
521 views

Django DB backup and restore

I am using Postgres in my Django project. My concern is regarding database backup and restore. Let's say I have a Django model named TestModel with name as a char field in that TestModel. I have ran ...
Bhavin Pokal's user avatar
0 votes
1 answer
89 views

In Django ORM, wildcard \b does not work (Postgres database) [duplicate]

All other wildcards work correctly but for example when I want to use "\bsome\b" pattern, it can't find any result however, there are many rows in the database that have a word "some&...
Mehrdad Salimi's user avatar

15 30 50 per page
1
2 3 4 5
21