I want to invoke a specific command shell in python to execute some scripts. For exemple, in R, I use: system2(os_shell = “C:/Program Files (x86)/pgAdmin III/1.18/pg_dump.exe”, args = “very long argument”) Thanks to this code, I can backup my Postgresql’s tables with a for loop. Problem: I didn’t find an equivalent in Python. Answer If you just want to execute
Tag: postgresql
Using SQLAlchemy 1.4 classical / imperative mapping style?
I am using the clean architecture & TDD development method in my Python project. Updating from SQLAlchemy 1.3 to SQLAlchemy 1.4 broke the ability to test against an in-memory Postgres DB, and I can’t find how to fix the problem. Following DDD principles, the project uses the new imperative mapping syntax which replace classical mapping declarations. Here is a minimal
How to create a summary table with subheadings in SQL?
I am using PostgreSQL to create summaries from data using a python script. I had large amounts of data in my SQL table and using the following query I was able to get the required data. Below is my query: And below is the table created: I am trying to create a query on this table to further create a
Create a new record with one2many
I want to create a new line in stock.picking, which will contain the date and the quantity: There’s no error,but the line is not created,SO I tried with There I have an error : only 2 args, 4 given. Is there another way to create a line of one2many Answer myRec.pack_lot_ids.create({‘id’: my_id,’qty’: myQty}) : this is correct you need to
How can i fetch my data from database to django template?
Whenever I run this, Exception Value: name ‘current_user’ is not defined; error is raised. I am not getting where i am doing the mistake as I m new in django programming. Please help me fetch the data Answer It looks like you will be getting that problem from showproduct(request) because you don’t define current_user in that method before calling it.
Django order a query by instance of ManyToMany
I have a model A with a ForeignKey to B: A ManyToMany relationship with an extra field that weight any B and C relation: And I need to order the A model (A.objects.filter(…)) using the weight of B2C for a given instance of C. For only one A instance I can do : But I don’t know how to do
Insert json data into postgres table using python
We have a python script which pulls data form an API endpoint this way: We got to this point and we do see the data in record_list, however we don’t know how to parse the data and insert it into a table. We tried: but it seems it is not a list, so what it is and how to import
ON CONFLICT DO UPDATE syntax and EXCLUDED error on cursor.executemany
I have a simplified postgres (ver 13) table below with updated rows generated in python with psycopg2. My question is when I update the price field in the rows, I can’t complete the update because of the following errors of ON CONFLICT DO UPDATE. If I don’t use ON CONFLICT DO UPDATE , I can update the chart but I
Django model saves when it shouldn’t
I’m trying to set custom validation rules on my Django models. I have the following code: Entity.py Security.py What I’m trying to do is to prevent a Security from being saved if its field entities holds more than 1 company. The entities field is a ManyToMany relationship with Entity, as it can hold multiple Asset objects but only one Company.
Can’t install own custom modules in Odoo 13
During the last two days I have been trying to install a custom module in Odoo 13. I got the same error over and over again, telling that a column didn’t exist in the model that I was creating (the variable in the class did, indeed, exist), I show the error down below. The python code of the module is