Can a Django admin user GUI disable a text box?

I have a Django model containing a text box. In the admin GUI, I would like to be able to filter only those entries that contain text in this field. Is it possible?

Code like this will filter the contents of the text box, but displays the filters on "All" and each individual entry in the filter. I would like to filter out "Everything" or "Contains something."

class MyModel(models.Model):
    # ...
    textfield = models.CharField(max_length=100)
    # ...

class MyModelAdmin(admin.ModelAdmin):
    list_display = ('...', 'textfield', '...')
    list_filter = ('...', 'textfield', '...')
+3
source share
3 answers

, . django\contrib\admin\filterspecs.py, , . 1.1, , HEAD: http://code.djangoproject.com/ticket/5833

, GET URL- change_list . /admin/app/model/?field1__lte=5&field2__gte=10 , ?field__isnull=True , , , .

+6

. . http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-filter

list_filter . BooleanField, CharField, DateField, DateTimeField, IntegerField ForeignKey.

...

.

  • .

    MyModel (models.Model):   #...   textfield = models.CharField(max_length = 100, blank = True)   #...

  • is_blank . , .

    def is_blank (self):   return len (self.textfield) == 0

-2

Source: https://habr.com/ru/post/1703709/


All Articles