I have an instance of ModelA and want to query all instances of ModelC which are related to ModelA through ModelB. ModelA -> all ModelB instances with FK rel_a = ModelA -> rel_c.all() I know how I would do this in SQL but I really do not get how I should unmangle these relations Answer You can query with a
Tag: django
Django sql statements with non english symbols
I have sql statement, with non english symbols in where (sap_code variable contains russian text) sap_code = ‘ОВОЩИ – ФРУКТЫ’ sql_string = ‘SELECT ‘ ‘SAP_CODE, ‘ ‘SKU, ‘ …
Double quotes problems with Postgres
I am using Django with postgres. Here’s the snippet of my code which I am using to create tables in the db. My question is: why is the user table getting renamed as “user” (with quotes) why is the role_id getting named as role_id_id where as I have clearly mentioned role_id to be my column name? Answer After reading few
How to fix traffic session table doesn’t exists error?
When I try to execute my code,I am getting this error? How could I resolve this issue? Answer I don’t know if you wrote this POST request or if it is a library or something. Could you please provide more info about it? As the error describes, it seems that: Make sure this table exists and it is available at
Django Sql ERROR 1064 when accessing table
I cannot access one of the tables in my database. I can’t even delete the table by myself, so I am not sure what to do. Here is the error: ERROR 1064 (42000): You have an error in your SQL syntax; …
Two foreign keys, only one can be not null at a time
I have a database table with two foreign keys pointing to two different tables. The business logic requires an “either or” relationship; only one foreign key can be NOT NULL at any given time. Here are the four possible states the foreign keys can hold based on the business logic: NULL, NULL – okay number, NULL – okay NULL, number
Django filter for all items which contain at least one null value
An answer elsewhere on SO provides the Postgresql NOT(<table> IS NOT NULL) query as an option to find all rows in a table containing one or more null values. How would one apply this query in the Django ORM without writing raw SQL? Or is this a case where raw SQL is required? I couldn’t find an example of such
How do I get Django to run a case-insensitive query against my MySql 5.7 db?
I’m using Django 2.0 and Python 3.7. I have this model and manager for attempting to find my model by a name, case-insentively. The backing database is MySql 5.7. Unfortunately, when the query actually gets created, it doesn’t appear Django is doing anything to account for case-insensitivity. This is an example query that results … What changes do I need
Django Reverse Regex Match
I have a table (Django Model) and each row/object contains a regular expression that I should evaluate over a given input to filter relevant objects. Is there any Django ORM method to do this? In Postgre it will be: and the opposite of what I am searching for is: I know that evaluating the regular expressions on the application side
In Django, how can I get a count of records based on a subquery of a subquery?
A baseball player plays in a game if he makes one or more appearances in that game. So, to get a count of the number of games a player played in, you need to count the games that have an inning that have an appearance by that player. Here are my models: The SQL query to achieve what I want