I created my first Django Trac ticket. Milestone?
-
Marijke Luttekesreplied to Marijke Luttekes last edited by [email protected]
@carlton The monkey patch might a lie, sadly.
I tried it in settings and in `AppConfig.ready()`, but I haven't gotten it to work yet.
It might work (I haven't checked regular forms yet), but I couldn't see its effects on the form sets where I needed this change.
Formsets, however, also seem to ignore the `Meta.widgets` attribute of its inner model form, so these issues might have a common ancestor.
-
Marijke Luttekesreplied to Marijke Luttekes last edited by
-
Carlton Gibson πͺπΊreplied to Marijke Luttekes last edited by
@mahryekuh Grrr. OK. I might have to play with that. Let me see...
-
Marijke Luttekesreplied to Carlton Gibson πͺπΊ last edited by
@carlton For completeness, this is the code I used, although it's very much based on what you provided:
```python
from django.db.models import fields
from django.utils.translation import gettext_lazy as _# Monkey patch:
# See also: https://code.djangoproject.com/ticket/35870
fields.BLANK_CHOICE_DASH = [('', _('(select an option)'))]
``` -
Carlton Gibson πͺπΊreplied to Marijke Luttekes last edited by
@mahryekuh Does this...
def get_choices(
self,
include_blank=True,
blank_choice=BLANK_CHOICE_DASH,
limit_choices_to=None,
ordering=(),
... mean it's set at class definition time? I think it might, which means it won't pick up the change. (I always have to think too hard about these cases, but that's likely the issue.) Bugger.
-
Carlton Gibson πͺπΊreplied to Carlton Gibson πͺπΊ last edited by
@mahryekuh You'll see the comment. Sorry for the mis-steer
-
Marijke Luttekesreplied to Carlton Gibson πͺπΊ last edited by
@carlton That's OK!
I am kind of surprised that the blank_choice kwarg even exists since, so far, I haven't seen it being used in core.
I don't know if a third-party package uses this kwarg, but it might be a blessing if we refactor this one.
(And with we, I mean that Thibaud has given himself ownership now)
-
Carlton Gibson πͺπΊreplied to Marijke Luttekes last edited by
@mahryekuh Go @thibaudcolas Go! π¦Έ
-
@mahryekuh Congratulations!
-
Alex Tomkinsreplied to Marijke Luttekes last edited by
@mahryekuh Ooh, yes please!
It's one we monkey patched ages ago, mostly as a design decision rather than for accessibility - but it would be a good one to make a bit easier to customise.
-
Marijke Luttekesreplied to Alex Tomkins last edited by
@alextomkins Do you remember how you monkey patched this thing? Carlton and I discovered that patching via Django settings and AppConfig.ready() doesnβt work.
-
Alex Tomkinsreplied to Marijke Luttekes last edited by [email protected]
@mahryekuh Adding it to settings.py - https://github.com/developersociety/django-template/blob/57b63bb25450ed6b78951fa5ba174bc8f46e39d0/%7B%7Bcookiecutter.project_slug%7D%7D/project/settings/base.py#L189
Although, just playing around with the code - it might not be a case of *where* it gets imported. Just tried changing it to `BLANK_CHOICE_DASH` - it doesn't override it, but `BLANK_CHOICE_DASH[0]` does.