2๐
You are overwriting the data
array at every loop step.
You need it to be something like this:
data=[
["Inspection_Id", "Licence_Plate", "Images", "Comment"],
["100", "TEST", "http://url.to/png", "Qwerty"],
["200", "2nd data row", "http://url.to/gif", "Dvorak"]
]
So that you can get something like
| Inspection_Id | Licence_Plate | Images | Comment |
| ------------- |-------------- | ----------------- | ------- |
| 100 | TEST | http://url.to/png | Qwerty |
| 200 | 2nd data row | http://url.to/gif | Dvorak |
Therefore, your loop needs to look like:
# Fill the first row of `data` with the heading, only once!
data = [[inspection, licplt, imgs, cmnts]]
try:
for i in damage_data:
inspection_data = str(i.inspection_id).encode('utf-8')
licence_plate = str(i.inspection.vehicle.licence_plate).encode('utf-8')
images = str(i.image).encode('utf-8')
comments = str(i.comment).encode('utf-8')
inspcdata = Paragraph(inspection_data, styleN)
lncplt = Paragraph(licence_plate, styleN)
img = Paragraph(images, styleN)
cmt = Paragraph(comments, styleN)
# Add this loop's step row into data array
data += [inspcdata, lncplt, img, cmt]
And that should be it ๐
And image data should be as the hyperlink.
What do you mean with this?
Cheers!
๐คraneq
1๐
If your main goal is to iterate and show the damage_data records in a table, then try the following:
(...)
damage_data = Damage.objects.all()
data = []
data.append(["Inspection_Id", "License_Plate", "Images", "Comment"])
try:
for i in damage_data:
row = []
inspection_data = str(i.inspection_id).encode('utf-8')
licence_plate = str(i.inspection.vehicle.licence_plate).encode('utf-8')
images = str(i.image).encode('utf-8')
comments = str(i.comment).encode('utf-8')
row.append(inspection_data)
row.append(license_plate)
row.append(images)
row.append(comments)
data.append(row)
(...)
This should iterate through your damage_data queryset and populate your table.
๐คstemado
- [Django]-Django send_mail get result
- [Django]-Django, is filtering by string faster than SQL relationships?
- [Django]-Django one to one relation queryset
- [Django]-Django: ValidationError using is_authenticated and logout when authenticating from an external source
- [Django]-How to fix Django error: " 'unicode' object has no attribute 'tzinfo' " on database read
Source:stackexchange.com