geex-arts / django-jet

Modern responsive template for the Django admin interface with improved functionality. We are proud to announce completely new Jet. Please check out Live Demo
https://github.com/jet-admin/jet-bridge
GNU Affero General Public License v3.0
3.57k stars 775 forks source link

Filtering with None #378

Open ceoro9 opened 5 years ago

ceoro9 commented 5 years ago

When you specify choices with None option on model field and in admin model set that field in filters, something really strange happens when you choose None option in pop up list, I mean everything works okay on backend, but here is the problem with styles.

# models.py
YES = "y"
NO = "n"
NOT_FOUND = None
YES_NO_CHOICES = (
    (YES, "yes"),
    (NO, "no"),
    (NOT_FOUND, "not completed"),
)

called_y_n = models.CharField(
        _("Called (Y/N)"),
        choices=YES_NO_CHOICES,
        max_length=10,
        null=True,
        blank=True,
        default=None,
        db_index=True,
    )

# admin.py
class Admin(admin.ModelAdmin):
    list_filter = ["called_y_n"]

1


When you choose not completed (None) option.

2

ljluestc commented 7 months ago
# models.py
from django.db import models
from django.utils.translation import gettext_lazy as _

YES = "y"
NO = "n"
NOT_FOUND = None

YES_NO_CHOICES = (
    (YES, _("yes")),
    (NO, _("no")),
    (NOT_FOUND, _("not completed")),
)

class YourModel(models.Model):
    called_y_n = models.CharField(
        _("Called (Y/N)"),
        choices=YES_NO_CHOICES,
        max_length=10,
        null=True,
        blank=True,
        default=None,
        db_index=True,
    )

# admin.py
from django.contrib import admin
from .models import YourModel

class YourModelAdmin(admin.ModelAdmin):
    list_filter = ("called_y_n",)

admin.site.register(YourModel, YourModelAdmin)