Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>"I would love to be able to create reports ... without having to code the reports" </p> <p>So would I. Sadly, however, each report seems to be unique and require custom code.</p> <p>From Django model to CSV is easy. Start there with a few of your reports.</p> <pre><code>import csv from myApp.models import This, That, TheOther def parseCommandLine(): # setup optparse to get report query parameters def main(): wtr= csv.DictWriter( sys.stdout, ["Col1", "Col2", "Col3"] ) this, that = parseCommandLine() thisList= This.objects.filter( name=this, that__name=that ) for object in thisList: write.writerow( object.col1, object.that.col2, object.theOther.col3 ) if __name__ == "__main__": main() </code></pre> <p>HTML is pretty easy -- Django has an HTML template language. Rather than render_to_response, you simply render your template and write it to stdout. And the core of the algorithm, interestingly, is very similar to writing a CSV. Similar enough that -- without much cleverness -- you should have a design pattern that does both.</p> <p>Once you have the CSV working, add the HTML using Django's templates.</p> <p>PDF's are harder, because you have to actually work out the formatting in some detail. There are a lot of Python libraries for this. Interestingly, however, the overall pattern for PDF writing is very similar to CSV and HTML writing.</p> <p>Emailing means using Python's <a href="http://docs.python.org/library/smtplib.html" rel="nofollow noreferrer">smtplib</a> directly or Django's <a href="http://docs.djangoproject.com/en/dev/topics/email/" rel="nofollow noreferrer">email</a> package. This isn't too hard. All the pieces are there, you just need to email the output files produced above to some distribution list.</p> <p>Scheduling takes a little thinking to make best use of <code>crontab</code>. This -- perhaps -- is the hardest part of the job.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload