In Django I have a SQL table with a column with a list of dates. The field is DATE.
In the views.py file I would like to get a list of the years from those dates. I have tried the following with no luck:
from mysite.WeatherData.models import WeatherData
time_list =[]
raw_time_list = WeatherData.objects.all()
for onedatum in raw_time_list:
time_list += onedatum.time_stamp.isocalendar()[0]
the column in WeatherData is called time_stamp and it holds the Date data.
The error I get is:
‘int’ object is not itterable.
I have done this with weeks of the year with WeatherData.objects.filter(location = LocationCode) and it worked fine so I’m not sure why this doesn’t work now.
You get that error because an integer cannot be appended to a list.
Here is an example to reproduce the error:
Applied to your code: