嗨,我有以下代码,我在 feature_list = 中有不同的元素['spa','castle','country_house','coast','golf','boutique','civil','private_hire','city','gay']
。在数据库中,值为 1 或 0。所以我试图检查它们是否为 1 并将它们附加到新数组中。
try:
hotel_main = models.Hotel.objects.get(slug=slug)
except models.Hotel.DoesNotExist:
try:
hotel_main = models.Hotel.objects.get(id=id)
except models.Hotel.DoesNotExist:
raise Http404
feature_list = ['spa','castle','country_house','coast','golf','boutique','civil','private_hire','city','gay']
hotel_features = []
for feature in feature_list:
if hotel_main.feature == 1:
hotel_features.append(feature)
它给了我以下错误:“酒店”对象没有属性“特征”
但在我的理解中,特征应该代表数组的字符串......请纠正我