|
7 | 7 |
|
8 | 8 | from django.apps import apps |
9 | 9 | from django.core.exceptions import ImproperlyConfigured |
10 | | -from django.db.models import AutoField |
| 10 | +from django.db.models import AutoField, CharField |
11 | 11 |
|
12 | 12 | from feincms import settings |
13 | 13 |
|
@@ -151,3 +151,19 @@ def get_singleton(template_key, cls=None, raise_exception=True): |
151 | 151 | def get_singleton_url(template_key, cls=None, raise_exception=True): |
152 | 152 | obj = get_singleton(template_key, cls, raise_exception) |
153 | 153 | return obj.get_absolute_url() if obj else "#broken-link" |
| 154 | + |
| 155 | + |
| 156 | +class ChoicesCharField(CharField): |
| 157 | + """ |
| 158 | + ``models.CharField`` with choices, which makes the migration framework |
| 159 | + always ignore changes to ``choices``, ever. |
| 160 | + """ |
| 161 | + |
| 162 | + def __init__(self, *args, **kwargs): |
| 163 | + kwargs.setdefault("choices", [("", "")]) # Non-empty choices for get_*_display |
| 164 | + super().__init__(*args, **kwargs) |
| 165 | + |
| 166 | + def deconstruct(self): |
| 167 | + name, path, args, kwargs = super().deconstruct() |
| 168 | + kwargs["choices"] = [("", "")] |
| 169 | + return name, "django.db.models.CharField", args, kwargs |
0 commit comments