Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
51 views

I've got these models: class Component(models.Model) name = models.CharField(max_length=50) class ComponentAttribute(models.Model) component = models.ForeignKey(Component) context = ...
Tschick Müller's user avatar
2 votes
1 answer
59 views

Let's take some Store and Book models as examples: class Book(Model): title = CharField(...) ... class Store(Model): books = ManyToManyField('Book', blank=True, related_name='stores') ...
Valkoinen's user avatar
0 votes
1 answer
90 views

Describe the Problem I have a ModelViewSet in Django REST Framework designed to return a list of Order objects. To improve performance, I'm trying to implement custom pagination that limits the ...
Raul Chiarella's user avatar
1 vote
1 answer
56 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
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
54 views

I am trying to get the book list with 3 conditions: Accession number (character varying,10) Physical location (character varying,20) Book status Based on the user input: Accession number should be ...
PM.'s user avatar
  • 1,731
0 votes
1 answer
72 views

I try to check - in Django - if a user-made queryset has two fields which match 100%. class Foo(models.Model): # ... free_field = models.ForeignKey(FreeModel, ...) must_match_m2m_field = ...
baloersch's user avatar
0 votes
1 answer
90 views

I'm currently developing a Gym website and using django-recurrence to handle recurring training sessions. However, I'm unsure how to work with recurrence dates in a Django QuerySet. Specifically, I ...
Dmytro Hryshchenko's user avatar
1 vote
1 answer
91 views

I have class Book(models.Model): title = models.CharField(max_length=32) class Table(models.Model): book = models.ForeignKey(Book, related_name='tables') class TableEntry(models.Model): ...
Daniel Krenn's user avatar
0 votes
0 answers
59 views

I've got an annotation for a foreign key field that I use frequently and would like to write a custom Django Transform which behaves similar to the annotation. The annotation that does what I would ...
bnett's user avatar
  • 1
0 votes
1 answer
58 views

In my Django project, I'm in need of a generic istruthy/isfalsy lookup that would work on any type of database field. Example of models.py: class MyModel(models.Model): my_charfield = models....
Luci's user avatar
  • 477
-1 votes
1 answer
73 views

I have model Report and GroupReport. They have many-to-many relation. I can easily get QuerySet[GroupReport] for all GroupReport instance: Group Name 1: Report Name 1 Report Name 2 Group ...
Qngdjas's user avatar
1 vote
0 answers
58 views

I have the following model: class Historique(models.Model): type_of_object_choices = ( (1, 'Cadeau') , (2, 'Offre') , (3, 'Commentaire') ) event_type_choices = ...
gibbe75's user avatar
  • 33
1 vote
0 answers
52 views

I'm debugging sitemap generation, and finally have the following snippet: items=Event.objects.all() for limit in (1000, 10000, 20000): events=items[:limit] ...
aikipooh's user avatar
  • 293
4 votes
1 answer
291 views

I have the following Django models: from django.db import models from django.utils.translation import gettext_lazy as _ class Enterprise(models.Model): nome = models.CharField(max_length=255) ...
Ives Furtado's user avatar
0 votes
1 answer
58 views

In the process of model annotation there is a need to filter the finished list. But the value of the annotation "rank" after the filter() becomes "1" because it has only one ...
darl1ne's user avatar
  • 426
0 votes
1 answer
73 views

I’m working on optimizing a complex Django query where I need to perform nested aggregations and conditional annotations across multiple related models. I want to fetch the top 5 most active users ...
user avatar
0 votes
1 answer
42 views

I'm failing to get Profiles whithout an Interaction. Does anybody see what I'm doing wrong? #models.py class Profile(models.Model): username = models.CharField(max_length=100) class ...
jjk's user avatar
  • 603
1 vote
1 answer
73 views

I have 3 django models; Machine, Component, and Part. I am trying to annotate a machine queryset to include the count of unique parts used in that machine. In the example below, ps1 is used to make f1....
Chris Parker's user avatar
-1 votes
1 answer
68 views

I want to filter directly on a lat/lng value on a GeoDjango PointField. e.g. geolocation__lat__lte=40.0 Typically in django i can access Latitude/Longitude directly like geolocation.x or geolocation.y ...
Kaizer's user avatar
  • 1
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
0 votes
0 answers
45 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
0 votes
2 answers
62 views

I have this Django Model : class Survey(models.Model): call = models.OneToOneField(Call, null=True, related_name='survey', on_delete=models.CASCADE) service = models.ForeignKey(Service, ...
Aurélien's user avatar
  • 365
0 votes
1 answer
59 views

I'm working on a Django application where I need to rank students based on their total points and then filter the results. I want to rank all students based on their total points but only show ...
Zaman Kazimov's user avatar
1 vote
1 answer
212 views

I'm facing a tricky problem and couldn't find a solution online. I hope someone here can help me figure out a "clean" way to do this. This is my current function to retrieve all expired ...
zdeneklapes's user avatar
0 votes
1 answer
80 views

Currently, I have two models posts.models from django.db import models from django_prometheus.models import ExportModelOperationsMixin from users.models import User from category.models import ...
Antoliny Lee's user avatar
-1 votes
1 answer
134 views

I'm having a hard time finding a decent explanation about this in django's official documentation, so I'll ask my question here. in django 5.0 if two models have a relationship (let's call them Model1 ...
confused coder's user avatar
2 votes
1 answer
100 views

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,165
1 vote
1 answer
68 views

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,080
2 votes
0 answers
45 views

I'm trying to create a custom django lookup as_int so that you can easily compare and order the contents of text fields when they contain only a number, and treat them as NULL when they have the wrong ...
Daniel Gordos's user avatar
1 vote
0 answers
37 views

I'm trying to populate a select item with a django queryset. It's working fine but at the begining of the list of the dropdown menu on the select item I always have a '---------' as first option. ...
Nico44044's user avatar
  • 399
1 vote
1 answer
33 views

I have three models like this: 1: class Blog(models.Model): title = models.CharField() published = models.DateField() ... 2: class AuthorList(models.Model): blog = models.ForeignKey(...
mr.xy's user avatar
  • 15
1 vote
1 answer
45 views

I have a model in which there are different fields of data, and a field of "section-order" is given. now i want to fetch that data into the bootstrap accordians with respect to the "...
Abheer Mehrotra's user avatar
0 votes
1 answer
110 views

Suppose that I have the following customer model: class Customer(models.Model): name = models.CharField() city = models.CharField() first_joined = models.DateField(auto_now_add=True) ...
Jalaj Kumar's user avatar
1 vote
1 answer
56 views

I'm trying to implement an autocomplete for an input field using Django and jQuery (user searches for a food from a menu). The problem is figuring out how to order the results. If, for example, the ...
Thomas Huitema's user avatar
0 votes
0 answers
36 views

I am learning django and couldn't find an answer on this. I am receiving data a query in denormalized form. Here is how it looks like. Store_id Shelf_id Product_id Qty store1 shelf1 product1 20 store1 ...
user1933205's user avatar
0 votes
1 answer
54 views

Suppose you have this models structure in a django project from django.db import models class Object(models.Model): name = models.CharField(max_length=100) class ObjectEvent(models.Model): ...
Zeno Dalla Valle's user avatar
1 vote
1 answer
42 views

I have a Notification model which has a field called seen_users like so: from django.contrib.auth import get_user_model User = get_user_model() class Notification(models.Model): title = models....
AbbasEbadian's user avatar
0 votes
1 answer
133 views

I did not use the Django for a years and tried to modify some old codebase today. I have models: class MetaTemplate(CreatedModifiedBase): type = models.CharField(max_length=200) class Project(...
Iwo Czerniawski's user avatar
1 vote
2 answers
52 views

Given the following model (using django-simple-history): class MyModel (models.Model): status = models.IntegerField() history = HistoricalRecords() I would like to get all instances that didn'...
Jmb's user avatar
  • 24.2k
-3 votes
1 answer
117 views

if I have a class like this: class Name: field1 = ... field2 = ... ... I do not know what are the fields or model it should be given by user so key is going to be name of field in a model and value ...
Tabasss_e's user avatar
0 votes
1 answer
33 views

What I have? I have models as below. class Product(models.Model): title = models.CharField(max_length=500) timestamp = models.DateTimeField(auto_now_add=True) updated = models....
AgentNirmites's user avatar
1 vote
1 answer
58 views

I'm trying to build a Django application where I have a ListView that displays a list of objects based on complex filtering criteria, but I'm encountering issues with the queryset not filtering ...
Shivʌm Singh Ʀathod's user avatar
0 votes
1 answer
81 views

There are two models: class Subject(Model): categories = ManyToManyField(Category, related_name='subjects') class Category(Model): parent = ForeignKey('self', related_name='subcategories') ...
Михаил Павлов's user avatar
1 vote
1 answer
78 views

I have a model for recipes and many-to-many model that represents favorite recipes by users: class Recipe(models.Model): author = models.ForeignKey(User, on_delete=models.CASCADE) name = ...
Anton's user avatar
  • 35
1 vote
1 answer
64 views

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

Sorry I am beginer in django try to make app for appointment for doctors and could not solved this problem I can't add value in to Appoiment Db in to django app this is my models.py from django.db ...
Via4eslav Tka4enko's user avatar
0 votes
1 answer
168 views

The django-tables2 docs describe how to sort a custom column (https://django-tables2.readthedocs.io/en/latest/pages/ordering.html#table-order-foo-methods). But I can't figure out how to apply this to ...
Mike's user avatar
  • 87
0 votes
0 answers
112 views

I have a Puzzle model and a Session model During a session, user will play puzzles and rate them. result is recorded through the following model: class Play(models.Model): puzzle = models....
Skratt's user avatar
  • 420
0 votes
1 answer
77 views

This is a follow up to a previous question but I will include all the detail here. I'm creating a game where one of the elements is that players vote for each other. Here are the models I've set up (...
phuefi's user avatar
  • 15

1
2 3 4 5
138