Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Admin list_filter not showing

So this is my code:

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)

I`m trying to add an admin filter to the Tasa model
but the filter it doesnt show on the admin

if i change the filter from "destino" to "nacionalidad" [ is the same main model("Destino") ] , i get the filter on the admin , and working ,with the list of all countries. Any king of help will be really apreciated. Thank you!

like image 933
Rus Mine Avatar asked Feb 20 '16 14:02

Rus Mine


People also ask

How do I access my Django admin page?

To login to the site, open the /admin URL (e.g. http://127.0.0.1:8000/admin ) and enter your new superuser userid and password credentials (you'll be redirected to the login page, and then back to the /admin URL after you've entered your details).

Does Django have admin panel?

One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin's recommended use is limited to an organization's internal management tool.

What is list filter in Django admin?

Django allows the user of the admin site to filter the instances of a Model by adding the list_filter attribute to your ModelAdmin objects. You can find more information about the Django's filtering utilities in the official documentation, in the Django Admin Site section.

What is admin in Django?

django-admin is Django's command-line utility for administrative tasks. This document outlines all it can do. In addition, manage.py is automatically created in each Django project.


1 Answers

Just found the solution . You need to have more than 1 "destinos" to show the list_filter.

like image 151
Rus Mine Avatar answered Oct 30 '22 01:10

Rus Mine