在 django 数据库中存储整数数组的最佳方法是什么?
我正在使用数组字段:https://docs.djangoproject.com/en/2.1/ref/contrib/postgres/fields/#querying-arrayfield https://docs.djangoproject.com/en/2.1/ref/contrib/postgres/fields/#querying-arrayfield
eg.
class Place(models.Model):
nearby_places_ids = ArrayField(models.IntegerField(null=True, blank=True), null=True, blank=True)
与用法:
place.nearby_places_ids = [1,2,3]
place.save()
models.Place.objects.filter(nearby_places_ids__contains=[1])
<QuerySet [<Place: Hostel DIC>]>
models.Place.objects.filter(nearby_places_ids__contains=[1,2,3,4])
<QuerySet []>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)