Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
70 views

I am trying to annotate a queryset with next_service = last_service + verification_periodicity_in_days and then filter by that date. I am on Django 5.2.6 with PostgreSQL. last_service is a DateField. ...
Richard AR's user avatar
1 vote
1 answer
46 views

I'm refactoring a legacy Django Job to use annotate with filtered Count aggregations instead of querying each record individually (avoiding the N+1 problem). I want to count the number of related ...
Raul Chiarella's user avatar
3 votes
1 answer
78 views

I'm building a secure OTP system in Django. The model looks like this: class OTP(models.Model): MAX_ATTEMPTS = 3 DEFAULT_EXPIRE_IN_MINUTES = 1 class Purposes(models.IntegerChoices): ...
Ertugrul's user avatar
  • 175
0 votes
1 answer
42 views

I'm encountering a ValueError in my Django application when trying to save a User object with a related UserRoleAssociation in the admin interface. The error occurs in a multi-database setup where ...
mirodil's user avatar
  • 439
2 votes
1 answer
95 views

If I have, for example: from django.contrib.postgres.fields import JSONField class MyModel(models.Model): data = JSONField() GIVEN a model instance obj1, where data == ['apple', 'banana', '...
Dane Iracleous's user avatar
1 vote
1 answer
60 views

I have this model: class KeyAccessLog(models.Model): key = models.ForeignKey( Key, related_name="access_logs", on_delete=models.CASCADE ) path = models.CharField(...
Mirza Delic's user avatar
  • 4,381
-3 votes
1 answer
83 views

I am trying to work out if it's possible/practical to use the Django ORM to get the highest value in an arbitrary timebox out of the database. Imagine a restaurant orders ingredients every day, we ...
David Downes's user avatar
  • 1,209
0 votes
0 answers
44 views

I'm not sure if the title of this post made you understand the problem but let me explain: I have models: class ItemCategory(models.Model): name = CharField() class Item(models.Model): brand =...
Antony_K's user avatar
  • 196
0 votes
1 answer
35 views

I have a simple queryset resulting from this: Books.objects.all() Books is related to Authors like this: Class Books: ... author = models.ForeignKey(Authors, on_delete=models.CASCADE) Class ...
Riccardo Lamera's user avatar
-1 votes
1 answer
45 views

class Company_Car(models.Model): @property def days_left(self): print("RUNNED PROPERTY") if self.date_valid is not None and self.date_valid >= datetime....
Yuretz's user avatar
  • 129
1 vote
3 answers
120 views

I have two model instances, rec1 and rec2, but each has different fields updated: rec1 = MyModel(id=1, name="John") # Only 'name' is changed rec2 = MyModel(id=2, age=30) # Only 'age'...
Shrijan's user avatar
  • 19
0 votes
1 answer
71 views

I'm trying to implement a simple search for data on a website. If we specify the a tag in the "search_results.html" template, then all the information that is in it is not displayed, but if ...
user28264793's user avatar
3 votes
1 answer
99 views

We are migrating our django app from django==3.2.25 to django==5.1.6. OneToOneField, ManyToManyField are giving errors on revers lookup. Create fresh setup. python -m venv app_corp_1.0.X ./app_corp_1....
NPatel's user avatar
  • 21.4k
0 votes
0 answers
103 views

Other related Questions mention using either django.db's close_old_connections method or looping through the django connections and calling close_if_unusable_or_obsolete on each. I've tried doing this ...
George's user avatar
  • 4,164
0 votes
1 answer
137 views

I'm using Func() Expressions to use this answer and compute the difference between two dates in business days: class BusinessDaysBetween(Func): """Implementation of a Postgres ...
Genarito's user avatar
  • 3,493
0 votes
1 answer
54 views

I am building a family tree application in Django where I need to represent and query marriages symmetrically. Each marriage should have only one record, and the relationship should include both ...
Anuj TBE's user avatar
  • 9,922
0 votes
1 answer
80 views

I'm annotating my QuerySet as follows, using JSONObject, to obtain multiple fields from Scan: MyModel.objects.annotate( myscan=Subquery( Scan.objects .all() .values(data=JSONObject(...
SaeX's user avatar
  • 19k
1 vote
2 answers
60 views

I'm trying to build following annotation, essentially looking up the nin field from a person either from the IDcard or from the Person model. .annotate( checkins_scan=Scan.objects.filter(models....
SaeX's user avatar
  • 19k
1 vote
1 answer
33 views

Assuming the following models: class Store(models.Model): name = models.CharField(max_length=255) class Stock(models.Model): name = models.CharField(max_length=255) store = models....
Ahmed Ashraf's user avatar
0 votes
1 answer
75 views

I have a query that uses the values from a subquery. While I'm able to write the subquery in django, I can't write the main query. Here's a little example (the schema is department <-- person <--...
Alessandro Salvetti's user avatar
1 vote
2 answers
72 views

I have trouble with updating calculating_special_order_items, calculating_floor_special_order_items, order_total, ship_total, confirm_total, real_total and calculating_total. When I save a new ...
sine's user avatar
  • 13
0 votes
0 answers
13 views

I'd like to use django.db.modles.query_utils.Q, the |-operator and defaultdict to create a (set-)union of different conditions, i.e. to filter anything that matches any of them. Therefore it makes ...
Herbert's user avatar
  • 5,685
1 vote
1 answer
37 views

Imagine I'm trying to count the number of tree cultivars in a certain park, and the trees are grouped in specific fields within the park. One catch is that trees can be replanted, so I want to count ...
afs76's user avatar
  • 114
1 vote
1 answer
160 views

I have stumbled into a bit of inconsistency with Foreign Keys and Generic Foreign Keys in Django. Suppose we have three models class Model_One(models.Model): name= models.CharField(max_length=255) ...
Gigerin's user avatar
  • 15
2 votes
1 answer
49 views

I'm trying to calculate a lookup for items sharing a common related object + a common value. As an informal summary, I want to use some form of: my_queryset.values(my_related_obj, my_date).annotate(......
Ziv's user avatar
  • 2,441
2 votes
2 answers
302 views

In Django I have custom QuerySet and Manager: from django.db import models class CustomQuerySet(models.QuerySet): def live(self): return self.filter(is_draft=False) class CustomManager(...
Matija Sirk's user avatar
  • 1,028
1 vote
3 answers
107 views

I've an Order model as below: class Order(models.Model): bill = models.ForeignKey(Bill, on_delete=models.PROTECT, null=True, blank=True) address_from = models.ForeignKey(Address, on_delete=...
Ahmed Ashraf's user avatar
0 votes
0 answers
20 views

An API in my project works fine locally but when it is called in production, it slows the application's response time (all other APIs) and the container workload gets throttled for about 10 seconds. ...
sajad's user avatar
  • 3
0 votes
2 answers
44 views

I have the following query: MyModel.objects.filter(foreing_key__value=F('value')) And It works perfectly. But now I have some complex rules where I need to evaluate the ForeignKey value depending on ...
Genarito's user avatar
  • 3,493
0 votes
1 answer
93 views

I have a complicated report in Django, which is written as raw SQL, and than stored in the database as a database view. I have a Django model (managed=False), tied to that database view, so that I can ...
Martin Taleski's user avatar
0 votes
0 answers
62 views

It started seemingly out of nowhere, I'm unable to trace the origins of this issue but yesterday I made migrations just fine and I'm the only working on the project as of now, when I run python manage....
Mazen Mamdouh's user avatar
-1 votes
3 answers
73 views

I have a table like: client_id action date (datetime) 1 visit 2024-10-10 10:00 1 visit 2024-10-10 12:00 1 visit 2024-10-10 13:00 2 visit 2024-10-10 13:00 So, I need to count amount of unique clients ...
Андрей's user avatar
0 votes
1 answer
54 views

I'm having a hard time constructing a query (sqlite) to get the latest message for each chatroom a user is part of. This is my model in Django: class Membership(models.Model): room_name = models....
gary's user avatar
  • 21
0 votes
1 answer
28 views

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
2 votes
1 answer
68 views

I have a Django codebase that does a lot of Case/When/ExpressionWrapper/Coalesce/Cast ORM functions and some of them sometimes need a field as an argument - output_field. from django.db.models import ...
Slava Pasedko's user avatar
1 vote
1 answer
44 views

I'm trying to run filters using methods in two separate attributes. In ICD10Filter: class Icd10Filter(filters.FilterSet): # New Filters for DOS Range dosFrom = filters.DateFilter(method='...
Azima's user avatar
  • 4,161
1 vote
0 answers
48 views

I store some temporary data in a database linked to a web socket. After a server reboot, the web sockets die and I want to delete all data from the corresponding table. Tell me where ideologically ...
Jolly Ray's user avatar
2 votes
1 answer
160 views

I'm trying to create a generated field that is also a foreign key to another table, while maintaining referential integrity at the database level. Basically, I'm trying to have the same effect as the ...
BlackHack's user avatar
1 vote
1 answer
253 views

I'm building a job board. Each Job could have several associated Location objects. I have designed my Location and Job models as follows: class Location(BaseModel): slug = models.CharField(unique=...
Sam Hosseini's user avatar
1 vote
0 answers
45 views

I'm encountering a significant performance difference when running the same raw SQL query in my Django application. The query executes in about 0.5 seconds in the Django shell but takes around 2 ...
Jakub Swistak's user avatar
2 votes
0 answers
62 views

The error I get is psycopg.OperationalError: consuming input failed: server closed the connection unexpectedly I am using RabbitMQ as my message broker, though I don't think it's related. Ultimately,...
David Sigley's user avatar
  • 1,198
-1 votes
1 answer
47 views

I'm trying to set my custom manager dynamically for given models. Here is a sample of my code class CustomManager(models.Manager): def active(self): return self.filter(name__startswith='c')...
MuhammadYusuf Rakhimov's user avatar
2 votes
1 answer
94 views

Assume I have those Django models: class Book(models.Model): title = models.CharField(max_length=100) class Author(models.Model): name = models.CharField(max_length=100) books = models....
Martin Thoma's user avatar
0 votes
1 answer
103 views

I have a Django model with a release_version char field that stores version information in the format 1.1.1 (e.g., 1.2.3). I need to sort a queryset based on this version field so that versions are ...
Ahsan Ahmad's user avatar
0 votes
1 answer
56 views

Each row in the paginated page makes a separate query for each “child” object, instead of prefetching the child objects (n+1 queries). model.objects.prefetch_related(Prefetch (lookup=“”, queryset=“...
Spinoza GL's user avatar
1 vote
3 answers
85 views

I have two models who inherit from another model. Example: class Parent(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name="ID") ...
Basti's user avatar
  • 63
0 votes
1 answer
41 views

I have a DB table which has a field "created_at". This is a auto_now_add=True field. This table is inserted data once everyday. What I want to do is filter data that corresponds to the last ...
Burakhan Aksoy's user avatar
1 vote
1 answer
27 views

I have two models: class ABSLoyaltyCard(models.Model): title = models.CharField( max_length=120, blank=True, ) class CardToOwner(models.Model): id = models.UUIDField(...
Андрей's user avatar
0 votes
0 answers
42 views

I have a Django model resembling the following: class SomeClass(CoreModel): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) auto_increment_id = models....
SercioSoydanov's user avatar
0 votes
0 answers
44 views

For example, the Invoice model has a project field that points a ForeignKey to the Project model, Project has a custom ProjectManager that has get_queryset defined, in get_queryset I do: super()....
Uoyroem's user avatar
  • 23

1
2 3 4 5
82