Background:
In a financial application I need to archive a set of reports at the
end of each reporting period, the model is reasonably complex but I
have 3 models of direct concern, a 'provision', 'period' and
'reportheader'. The code is correctly generating the reports and they
are archived in a subdirectory under the media root and the
'reportheader' information in the MySQL database looks perfectly fine.
Problem is that I can not read the information back from the
database. I have tried to read a single report header specifying the
pk=1 (MySQL Query return the record just fine) and get the error
reported in the subject line raised from the 'get'. Of course what I
really want is to get the related set of reports from the period, but
the code to do that returns an empty querySet.
Model code:
class ReportHeader(models.Model):
"""comment"""
provision = models.ForeignKey(Provision, null=False, blank=False)
period = models.ForeignKey(Period, null=False, blank=False)
report_name = models.CharField(max_length=100, null=False)
# couple of othe field definitions
saved_file = models.FileField(upload_to="reports", null=True,
blank=True)
def __init__(self, request, *args, **kwargs)
self.provision=request.provision
self.period=self.provision.get_current_period()
Report Generation Code:
filename, report = report_generator.report(request)
report_header=ReportHeader(request)
report_header.report_name=report_name
load = InMemoryUploadedFile(file=report,
field_name=report_header.saved_file, name=filename,
content_type="application/pdf", size=report.tell(), charset=None)
report_header.saved_file=load
report_header.save()
Failing Code:
def reports_list(request, period_id)
# some other irrelevant code
try:
reportheader=ReportHeader.objects.get(pk=1
except Exception, e:
pass
return render_to_response("reports_list.html, locals(),
context_instance=RequestContext(request))
Sample database content:
id provision_id period_id
report_name ..... saved_file
1 1 4 Net Income Per
Book reports/NIPBQ12010AllCompanies.pdf
Does anyone have a clue why the simple get is failing?
Thank You.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.