|
1 | 1 | from admin_auto_filters.filters import AutocompleteFilter as BaseAutocompleteFilter |
| 2 | +from django.contrib import messages |
2 | 3 | from django.contrib.admin.filters import FieldListFilter, SimpleListFilter |
3 | 4 | from django.contrib.admin.utils import NotRelationField, get_model_from_relation |
4 | | -from django.core.exceptions import ImproperlyConfigured |
| 5 | +from django.core.exceptions import ImproperlyConfigured, ValidationError |
5 | 6 | from django.db.models.fields import CharField, UUIDField |
6 | 7 | from django.urls import reverse |
7 | 8 | from django.utils.translation import gettext_lazy as _ |
@@ -107,3 +108,17 @@ class Media: |
107 | 108 |
|
108 | 109 | def get_autocomplete_url(self, request, model_admin): |
109 | 110 | return reverse('admin:ow-auto-filter') |
| 111 | + |
| 112 | + def __init__(self, *args, **kwargs): |
| 113 | + try: |
| 114 | + return super().__init__(*args, **kwargs) |
| 115 | + except ValidationError: |
| 116 | + None |
| 117 | + |
| 118 | + def queryset(self, request, queryset): |
| 119 | + try: |
| 120 | + return super().queryset(request, queryset) |
| 121 | + except ValidationError as e: |
| 122 | + error_msg = ' '.join(e.messages) |
| 123 | + messages.error(request, error_msg) |
| 124 | + return queryset |
0 commit comments