0
我試圖篩選在我的管理類電路模型類與外鍵字段對象:模型對象過濾不起作用
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "current_firmware":
kwargs["queryset"] = FirmwareVersion.objects.filter(firmware__circuit_model=self.model)
return super(CircuitAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
我想不通爲什麼,但對於外地選項列表過濾後current_firmware
爲空。也許任何人都可以幫助我。 我已經得到了這些類:
class FirmwareVersion(models.Model):
firmware = models.ForeignKey(Firmware)
version = models.CharField(max_length=100)
class Firmware(models.Model):
name = models.CharField(max_length=250)
circuit_model = models.ForeignKey(Versiiplates)
class Versiiplates (Model):
version = ForeignKey(Plates)
nomer_oboznachenie = CharField(max_length=8)
class Circuit(models.Model):
circuit_id = models.PositiveIntegerField(blank=True, null=True)
model = models.ForeignKey(Versiiplates)
current_firmware = models.ForeignKey(FirmwareVersion, blank=True, null=True)