欢迎,
我在限制与 ForeignKey 相关的选择方面遇到了一些问题。下面我附上我的代码片段(models.py):
class Car(models.Model):
name = models.CharField(max_length=50)
....
class Driver(models.Model):
name = models.CharField(max_length=50)
car = models.ForeignKey(Car)
....
class CarForm(ModelForm):
class Meta:
model = Car
class DriverForm(ModelForm):
def __init__(self, *args, **kwargs):
super (DriverForm,self).__init__(*args, **kwargs)
self.fileds['car'].queryset = Car.objects.filter(???_1_???)
class Meta:
model = Driver
谁能给我一些建议应该如何定义???1???仅将可用的 Car 对象限制为未分配给任何 Driver 的对象?