我需要在 list_filter 中使用内联类的字段,在我的操作中,我的操作需要字段才能工作。查询是最好的方法吗?
管理员.py
class TelefoneIPInline(admin.StackedInline):
model = MovimentoTelefoneIP
extra = 1
list_filter = ['nome']
class TelefoneIPAdmin(admin.ModelAdmin):
def cliente():
movimento = MovimentoTelefoneIP.objects.filter(id = 1)
for cliente in movimento:
cli = cliente.cliente
return cli
cliente = cliente()
file = open('lala', 'w')
file.write(str(cliente))
list_display = ('mac', 'modelo', 'fornecedor', )
search_fields = ['mac']
inlines = [TelefoneIPInline]
模型.py
class TelefoneIP(models.Model):
mac = models.CharField(max_length=12, help_text="Este campo deve ter 12 digitos")
modelo = models.ForeignKey(ModeloTelefoneIP)
fornecedor = models.ForeignKey(Fornecedor)
datacompra = models.DateField(verbose_name="Data de compra", null=True, blank=True)
nfcompra = models.IntegerField(verbose_name="Nota fiscal de compra", blank=True, null=True)
obs = models.TextField(max_length=500, null=True, blank=True)
class MovimentoTelefoneIP(models.Model):
equipamento = models.ForeignKey(TelefoneIP)
cliente = models.ForeignKey(Cliente)
sentido = models.ForeignKey(sentido)
nfentrada = models.IntegerField(verbose_name="Nota fiscal de entrada", null=True, blank=True)
dataentrada = models.DateField(verbose_name="Data de entrada", null=True, blank=True)
nfvenda = models.IntegerField(verbose_name="Nota fiscal de saída", null=True, blank=True)
datavenda = models.DateField(verbose_name="Data de saída", null=True, blank=True)