I have the listview working, and I tested a def in the shell, so now I'm tring to pass the returned result from the def through the listview so I can display the value in the html. So the problem is, how to do this?
Here is the def, it is passing some raw sql which compares two tables in two different schemas to show the user how many records need updating.
def count_new_rows():
with connection.cursor() as cursor:
cursor.execute("""
SELECT count(*)
FROM samples.samples a
FULL OUTER JOIN kap.sample b
ON a.area_easting = b.area_easting AND a.area_northing = b.area_northing AND a.sample_number = b.sample_number AND a.context_number = b.context_number
WHERE
(a.area_easting IS NULL AND a.area_northing IS NULL AND a.sample_number IS NULL AND a.context_number IS NULL)
OR
(b.area_easting IS NULL AND b.area_northing IS NULL AND b.sample_number IS NULL AND b.context_number IS NULL)
""")
count = cursor.fetchall()
return count
And here is the functioning listview
class SampleListView(generic.ListView):
template_name = 'sample/sample_list.html'
model = Sample
paginate_by = 50
queryset = Sample.objects.filter(sample_type='Organic')
Do I add the following? If so how do I access the data on the html side?
data = count_new_rows()