您好我有zipcodes列表
zipcodes = ['1234', '2132', '12312', '123123', '12317']
我创建了一个事件模型如下:
class Event(models.Model):
title = models.CharField(max_length=40)
description = models.CharFi
address = models.TextField(max_length=350, null=True, blank=True)
city = models.CharField(max_length=50, blank=True, null=True)
state = models.CharField(max_length=50, blank=True, null=False)
province = models.CharField(max_length=50, blank=True, null=False)
zipcode = models.CharField(max_length=10, blank=True)
现在对于给定的zipcodes列表,我需要获取所有事件对象。如何在django中为此编写查询?
答案 0 :(得分:2)
使用in
:
zipcodes = ['1234', '2132', '12312', '123123', '12317']
Event.objects.filter(zipcode__in=zipcodes)