0
내가 예를 들어 모델의 querysets
이모든 쿼리 세트에 필드를 추가 할 수 있습니까? 장고
class ModelA(models.Model):
name = models.Charfield(max_length=256)
ageMin = models.IntegerField(null=True, blank=True)
ageMax = models.IntegerField(null=True, blank=True)
def age(self):
low = self.ageMin
high = self.ageMax
if low and high:
return str(low) + ' - ' + str(high)
if low:
return str(low)
if high:
return str(high)
는이 전 등이다 age_gap
라는 이름의 필드로 실제로 모두의 검색어에 필드를 추가 할 ModelA
의 모든 수익을 얻을 수있는 검색어 세트가 있다고 가정 해 보자 모델 자체의 def age
은 각각의 쿼리 세트가 gap_gap
이 아닌 이 아닌
이라는 필드를 추가로 갖습니다.하지만 다음과 같이 시도했지만 작동하지는 않습니다. 물론이의 Q [ 'age_gap'] = q.age()
: 위의
all_q = ModelA.objects.filter()
qs = map(lambda x: x.update({'age_gap': x.age()}), all_q)
작동하지 않습니다 그래서 나는 all_q의 질문에 대한 뭔가를하려고 생각 나에게 너무 오류를 준다.
누군가가 나를 어떻게 할 수 있겠 니? 사전
이 아무것도 사용할 수 있습니까? – kevswanberg