【问题标题】:Django Admin list_filter not showingDjango Admin list_filter 未显示
【发布时间】:2016-06-02 03:43:06
【问题描述】:

这是我的代码:

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”)],我会在管理员上获得过滤器,并且工作,与所有国家的名单。 任何帮助之王都会非常感激。 谢谢!

【问题讨论】:

    标签: python django python-2.7 django-admin


    【解决方案1】:

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

    【讨论】:

    • 哇,谢谢!今天遇到了这个问题。真正出乎意料的行为,但有道理。
    • 这很令人困惑。这种行为是否记录在案?
    • 今天我在同一主题上遇到了不同的问题。如果您有自定义过滤器,并且如果您在 lookups 上返回空列表而不是 [(None, None)],则不会显示。
    猜你喜欢
    • 2013-05-15
    • 2012-03-30
    • 2012-04-06
    • 2018-06-25
    • 2015-01-08
    • 2015-03-16
    • 2012-02-19
    • 2012-10-18
    • 2020-09-20
    相关资源
    最近更新 更多