Ich hatte viele Automarken, aber nicht so viele Autos. Ich brauche nur Automarken, die Autos haben.Holen Sie sich Modellobjekte in Modell desselben Modells
Problem ist, wie man diese CarForRent.objects.all() im CarForRent Modell nennt?
Hier ist, wie ich versuche, dies zu tun:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
from information.models import CarBrand, CarModel, City
class CarForRent(models.Model):
owner = models.ForeignKey(User)
brand = models.ForeignKey(CarBrand)
model = models.ForeignKey(CarModel)
years = models.CharField(max_length=4, choices=CAR_YEAR_CHOICES)
consumption = models.DecimalField(max_digits=5, decimal_places=2, blank=True)
body_type = models.CharField(max_length=21, choices=BODY_TYPE_CHOICES)
fuel_type = models.CharField(max_length=21, choices=FUEL_TYPE_CHOICES)
transmission_type = models.CharField(max_length=4, choices=TRANSMISSION_TYPE_CHOICES)
doors = models.CharField(max_length=4, choices=DOOR_TYPE_CHOICES)
air_conditioner = models.BooleanField(default=True)
def get_active_car_brands(self):
brands = []
active_brands = []
----------> for car in CarForRent.objects.all(): <--------- problem
brands.append(car.brand)
for brand in brands:
active_brands.append(CarBrand.objects.get(id=brand))
return active_brands