gpt4 book ai didi

python - Django Admin list_filter 未显示

转载 作者:太空狗 更新时间:2023-10-29 22:06:32 27 4
gpt4 key购买 nike

所以这是我的代码:

class Destino(models.Model):
paisid = models.IntegerField(blank = True,null = True)
nombre = models.CharField(max_length = 200)
grupo = models.CharField(max_length = 200, blank = True, null = True)
requisitos_turismo = models.ManyToManyField(Requisito, related_name = "requisitos_turismo", blank = True)
requisitos_negocios = models.ManyToManyField(Requisito, related_name = "requisitos_negocios", blank = True)
dias_min_entrada = models.IntegerField(blank = True,null=True)
importancia = models.CharField(max_length = 200, default = "15")
enlace = models.CharField(max_length = 200,blank = True,null = True)
imagen = models.ImageField(upload_to="img", null = True,blank = True)
# formulario = models.ForeignKey('Formulario', related_name = "destino_formulario", blank = True,null = True)
def __unicode__(self):
return self.nombre


class Tasa(models.Model):
nacionalidad = models.ForeignKey(Destino, related_name = "nationality")
destino = models.ForeignKey(Destino, related_name = "destination")
duracion_dias = models.IntegerField(blank = True,null = True)
tipo_visado = models.ForeignKey(TipoVisado, blank = True,null = True)
motivo = models.ForeignKey(Motivo, blank = True, null = True)
precio = models.DecimalField(max_digits = 6, decimal_places = 2, blank = True, null = True)
def __unicode__(self):
return "%s,%s,%s,%s,%s,%s" % (self.nacionalidad.nombre,self.destino.nombre,str(self.duracion_dias),self.motivo.nombre,self.tipo_visado.nombre,self.precio)

class AdminTasas(admin.ModelAdmin):
search_fields = ['nacionalidad__enlace']
ordering = ('nacionalidad__enlace',)
list_filter = (
('destino', admin.RelatedOnlyFieldListFilter),
)

admin.site.register(Tasa,AdminTasas)

我正在尝试向 Tasa 模型添加管理过滤器
但它没有显示在管理员上的过滤器

如果我将过滤器从“destino”更改为“nacionalidad”[是相同的主要模型(“Destino”)],我会在管理员上获得过滤器,并使用所有国家/地区的列表。任何国王的帮助都会非常感激。谢谢!

最佳答案

刚刚找到解决方案。您需要有超过 1 个“destinos”才能显示 list_filter。

关于python - Django Admin list_filter 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35524427/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com