History: I have been using GNUCash for Accounting and it stores all customer information so to integrate Job Delivery of files and invoices i was integrating GNUCash database on Postgres with the existing local server to send and backup files and mark them automatically.
So i did inspectdb> models.py
and got all the models from gnucash database.
Now 'Customers.objects.all()' is working file and gives list of all the data but 'Customers.objects.get()' doesn't work and gives error.
View:
def get_job_list(client_id):
try:
client = Customers.objects.get(id = client_id).using('gnucash')
print(client)
###job_list = Jobs.objects.get(owner_guid = client.guid,active = 0).using('gnucash')
except Exception as e:
job_list = None
return job_list
The above error states that the table doesn't exist customers.
But when i change the code to Model.objects.all()
it works fine.
View:
def get_job_list(client_id):
try:
client = Customers.objects.all().using('gnucash') #This is Changed
print(client)
job_list = None
###job_list = Jobs.objects.get(owner_guid = client.guid,active = 0).using('gnucash')
except Exception as e:
job_list = None
return job_list
I looked at This question which focuses on lowecase table name which is correct for me as .all()
work but not .get()
.
Here is model if you want to take a look:
class Customers(models.Model):
guid = models.CharField(primary_key=True, max_length=32)
name = models.CharField(max_length=2048)
id = models.CharField(max_length=2048)
notes = models.CharField(max_length=2048)
active = models.IntegerField()
.
.
.
class Meta:
managed = False
db_table = 'customers'
Using Hardcoded Values in .get
as suggested by @boyenec:
def get_job_list(client_id):
try:
print("Getting Jobs List")
#client = Customers.objects.filter(id__in=[client_id]).using('gnucash')
client = Customers.objects.get(id = "CUS000001").using('gnucash')
#job_list = Jobs.objects.filter(owner_guid__in = [client[0].guid],active__in = [1]).using('gnucash')
except Exception as e:
print("Oh No Error !")
print(e)
job_list = None
return job_list
App ERP registered with Admin site:
UPDATE:DO NOT USE THIS CHECK OUT THE ANSWER IT SOLVES THE PROBLEM
I Started using
client = Customers.objects.filter(id__in=[client_id]).using('gnucash')
for the queries as everything seem to work other thanModel.objects.get()