I am new to python, I am currently developing an application, which is responsible for generating several very simple reports, however there is a report which I have not yet been able to solve, I have researched but I still can not find the solution.
Basically what I want to do is the following SQL query through the ORM:
select log.* from file_managerfiles as file, log_managerlog as log where log.fileLog_id = file.id and file.lastUpload = TRUE
the models are the following:
class ManagerFiles(models.Model):
filesUpload = models.FileField(upload_to='log', unique=True)
processingStatus = models.BooleanField(default=False)
lastUpload = models.BooleanField(default=True)
class ManagerLog(models.Model):
date = models.CharField(max_length=10)
time = models.CharField(max_length=30)
serialNumber = models.CharField(max_length=30)
sessionID = models.CharField(max_length=50)
moduleName = models.CharField(max_length=50)
operationName = models.CharField(max_length=100)
operationSpecific = models.TextField(max_length=500)
fileLog = models.ForeignKey(ManagerFiles)
Within the last model (ManagerLog) create a method that returns all records of the ManagerLog model where ManagerFile.lastUpload equals TRUE:
# Report Last Upload File
def report_last_upload(self):
return self.__class__.objects.filter(ManagerFiles__lastUpload=True)
However when calling this method (report_last_upload) in my view, I get the following error:
raise AttributeError ("Manager is not accessible via% s instances"% cls. name ) AttributeError: Manager is not accessible via ManagerLog instances
I do not understand what the problem is, I hope you can help me, and thank you in advance