Example (this one breaks):
{{{
def create_option(self, name, value, label, selected, index,
subindex=None, attrs=None):
context = super().create_option(name, value, label, selected,
index, subindex, attrs)
if not value:
return context
if value in self.show_fields: # This is a dict {1: ['first_name',
'last_name']}
context['attrs']['data-fields'] =
json.dumps(self.show_fields[value])
}}}
However, working with arrays is not an issue:
{{{
def create_option(self, name, value, label, selected, index,
subindex=None, attrs=None):
context = super().create_option(name, value, label, selected,
index, subindex, attrs)
if not value:
return context
if value in allowed_values: # This is an array [1, 2]
...
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33155>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Bug => Cleanup/optimization
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Thanks for the ticket. Agreed, we could make `ModelChoiceIteratorValue`
hashable by adding:
{{{
def __hash__(self):
return hash(self.value)
}}}
For now you can use `value.value` as
[https://docs.djangoproject.com/en/3.2/releases/3.1/#id1 documented in the
"Backwards incompatible changes in 3.1" section].
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:1>
Comment (by Aljaž Košir):
Replying to [comment:1 Mariusz Felisiak]:
> Thanks for the ticket. Agreed, we could make `ModelChoiceIteratorValue`
hashable by adding:
> {{{
> def __hash__(self):
> return hash(self.value)
> }}}
> For now you can use `value.value` as
[https://docs.djangoproject.com/en/3.2/releases/3.1/#id1 documented in the
"Backwards incompatible changes in 3.1" section]. Would you like to
prepare a patch?
Yes, sure.
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:2>
* owner: nobody => Aljaž Košir
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:3>
* has_patch: 0 => 1
Comment:
Patch: https://github.com/django/django/pull/14915
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:4>
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:5>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:6>
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:7>
* type: Cleanup/optimization => Bug
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"7b8beeee3d45cafd7bec7ff3ee0e4371e142c36d" 7b8beee]:
{{{
#!CommitTicketReference repository=""
revision="7b8beeee3d45cafd7bec7ff3ee0e4371e142c36d"
Fixed #33155 -- Made ModelChoiceIteratorValue instances hashable.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:9>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"0a49276065575867fbbf279f138b399c535e3b6d" 0a492760]:
{{{
#!CommitTicketReference repository=""
revision="0a49276065575867fbbf279f138b399c535e3b6d"
[4.0.x] Fixed #33155 -- Made ModelChoiceIteratorValue instances hashable.
Backport of 7b8beeee3d45cafd7bec7ff3ee0e4371e142c36d from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33155#comment:10>