【发布时间】:2020-06-24 15:01:38
【问题描述】:
我正在使用带有 django-address 模块的 Django 3 和 Python 3.7 -- https://github.com/furious-luke/django-address。特别是它提供了两种模型...
Country
name
code
State
name
code
country -> Country
如何根据特定国家/地区代码搜索州?如果我只是按主键搜索,我可以写
def get_object(self, pk):
try:
return State.objects.filter(country=pk)
except Coop.DoesNotExist:
raise Http404
但是,如果我使用国家代码搜索州,我不清楚如何编写 Django 查询。
【问题讨论】:
标签: python-3.x django django-models filter