Having two tables, one of them is called Tasks and the other one Relations where every task in Tasks might have 0-to-many predecessors and similarly, 0-to-many successors that relations among tasks are stored in the Relations-table. So, if Task_1 is predecessor of Task_2 and Task_2 is predecessor of Task_3 then I would like to store the following records in the
Tag: django
Foreign key relationship with boolean values
I’m working on a feature. I’ve three different car types (Sedan, Hatchback, SUV): I’ve 6 features in total. Out of 6, 4 features are their in every car. The second car category has 5 and the third has all the 6 features. Here where I’m getting stuck: I’ve to send all the 6 features in all the categories to the
Sum of column values inside Json array with group by
I have next Django model. I store JSON data in wh_data. Note: it’s data for one row – 2022-06-06. I need to calculate the sum inside stocks by grouping them by wh and by created_at so that the output is something like this I know how to group by date, but I don’t understand how to proceed with aggregations inside
How to compose Django Model Filter for relation existence?
There is a many-to-many relationship between A and B. There are 3 tables to represent that relationship. TableA, TableB, TableAB Now I have another table TableC where it has a foreign key to TableA, and I want to filter objects from TableC where it has a relationship with TableB. The following is high-level code to give you the idea how
django ‘dict’ object has no attribute ‘job_id’
I’ve got this code: Even though value() is defined, I get the error ‘dict’ object has no attribute ‘job_id’ I guess the error will also be for pass_count, skip_count and fail_count What am I supposed to do here? Answer Your query does not return a queryset with object instances, so you cannot refer to fields with a “.” It is
Is it possible to delete last n records of a django model in one/minimum database query?
I’m trying to delete last 10 records of Task table/model in django but I’m unable to do that in one query. Above code gives me error AttributeError : ‘list’ object has no attribute ‘delete’. If I make a loop and then use .delete() on each object of that list then it will call db n times which I don’t want,
Transforming SQL Query to Django Expression
Assuming I have the following Django models and the according SQL-Tables with some data. I have simplified the models so that it is clearer. UserAnswer: id answer partquestion_id 1 667 1 PartQuestion: id question_id part_id 1 1 1 Solution: id content question_id 1 667 1 2 85 2 I want to get all User answers where the answer is equal
Extract JSON content in Metabase SQL query
Using: Django==2.2.24, Python=3.6, PostgreSQL is underlying DB Working with Django ORM, I can easily make all sort of queries, but I started using Metabase, and my SQL might be a bit rusty. The problem: I am trying to get a count of the items in a list, under a key in a dictionary, stored as a JSONField: Example of the
Django ORM Left Join onto same table
I have a custom permissions system in a django project that can link any user to any specific model instance to grant permission on that object. It is more complex than this, but boiled down: I want to query for all permissions for any user, that are linked to the same content_object(s) that a particular user has been granted permission(s)
Django ORM compare tuples / lexicographic ordering
As part of some custom cursor-based pagination code in Python Django, I would like to have the below filtering and ordering on a generic Queryset (where I don’t know the table name up front) How can this be expressed in terms of the Django ORM? Note I would like the SQL to keep the tuple comparison and not have this