2👍
✅
The problem is in your items
method, not your location
method. The items
method is what generates the list of items in the site map, the location
method is just supposed to return one location given the one item it is passed as its obj
parameter.
So try this:
def items(self):
return fruitmodel.objects.distinct('name')
def location(self, obj):
return '/day/%s' % obj.name
Edit: the above seems to work only in PostgreSQL (I think). For databases that don’t support DISTINCT ON
, you could try:
def items(self):
return list(set([f.name for f in fruitmodel.objects.all()]))
def location(self, obj):
return '/day/%s' % obj
But I think a better solution would be to factor your model so that name
is actually unique, and have the dates as related objects.
Source:stackexchange.com