I am a bit confused about how I will populate the following csv function with information in my models.py for a given user. Can someone point me in the right direction? Do I need to process the information in the separare py file file, or can I do this in my views?
My opinion is to download information
def download(request): response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=UserData.csv' writer = csv.writer(response) writer.writerow(['Date', 'HighBGL', 'LowBGL', 'Diet', 'Weight', 'Height', 'Etc']) writer.writerow(['Info pertaining to date 1']) writer.writerow(['info pertaining to date 2']) return response
One of the models that I'm interested in saving
class DailyVital(models.Model): user = models.ForeignKey(User) entered_at = models.DateTimeField() high_BGL = models.IntegerField() low_BGL = models.IntegerField() height = models.IntegerField(blank = True, null = True) weight = models.IntegerField(blank = True, null = True)
source share