관리자 용 차고 및 자동차를 만듭니다. 현재 차고에있는 모든 차량의 금전적 가치를 계산하려고합니다.중급 모델 Django ORM
def price_of_cars(request):
garages = Garage.objects.filter(..) #
total_price_of_cars_in_this_garages = 0
for a in garages:
for p in garages.cars:
total_price_of_cars_in_this_garages += (p.price * how_much)
return render_to_response('garage.html',
{'total_price_of_cars': total_price_of_cars_in_this_garages})
하지만 반환 :
class Car(models.Model):
name = models.CharField(max_length=50)
price = models.DecimalField()
class GarageCar(models.Model):
car = models.ForeignKey('Car')
how_much = models.IntegerField()
class Garage(models.Model):
name = models.CharField("Garage_Name", max_length=30)
cars = models.ManyToManyField('GarageCar', blank=True, null=True)
나는 이런 식으로 뭔가를 시도 구문 오류가 나는 how_much
반환 오류 삭제하는 경우 : 'ManyRelatedManager'개체가