2π
β
If you are using postgres, then you can use the distinct
queryset filter with a field name.
class BrowseLocationsPageView(ListView):
def get_queryset(self):
return self.model.objects.distinct('name')
This solves the βissueβ but there is a bigger problem at hand. Wherever you are creating the countries, you are creating new countries instead of looking if there is an existing country with the same name β get_or_create
may be useful here.
Location should probably have a foreign key to a country tooβ¦
π€Sayse
0π
You have country as a CharField in the Location Model. Hence the repitition.
Change the country field as a ForeignKey in the Location model
π€Aswin Murugesh
Source:stackexchange.com