[Answer]-Populating a database in django and retrieving the values in the view gives error becaue of ForeignKey?

1👍

If you look at the url in your admin view, are the primary keys of the two weeks in the database really 1 (and 2)? It is possible that if you tested the generating script more than once (or maybe played with the database before) the two records just happen to have other primary keys than 1 (or 2).

Also, if you want a specific record you could query by each of the model’s fields, e.g. Week.objects.get(date='my_hardcoded_date'). (by the way, I guess the value in date is something customized, so that you can’t use one of Django’s native DateField or DateTimeField).

👤sthzg

Leave a comment