Django QuerySet returns nothing

一世执手 提交于 2019-12-02 07:29:54

The problem is you are trying to match country__name to country_id. Alter the last line in get_queryset to become return City.objects.filter(country__id=country_id) which will now filter the country_id supplied against City's country id.

May be your returning query is wrong,

class Country(Models.model):
     country_id=Autofield()
     country_name=CharaField()

in Views.py

def get_queryset(self, *args, **kwargs):
    country_id = self.kwargs.get('country_id')
    return City.objects.filter(country_id=country_id)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!