Replies: 1 comment
-
I can see that I can bring support for a custom class to Unicorn by adding the class AccountType(IntegerChoices):
PERSON = 1, _("Single Person")
COMPANY = 2, _("Company/Business")
@classmethod
def to_json(cls):
return [
{
"value": value,
"label": label,
}
for value, label in cls.choices
] This does not work, asI want the class here, and the It feels bad to redefine |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a component that needs to check against a enum or IntChoices class in the template:
The component itself looks like this:
I use the class itself in the template, to check against a proper name, and not against hardcoded "1" or "2".
This worked "before" Unicorn, with plain Django w/ HTMX.
When the page is rendered the first time, it works, but when clicking on any unicorn-enabled button, and the component is rendered again using the AJAX call, the
AccountType
variable is not in the context.If I just replace it with
AccountType = "foo"
in the component, it is correctly rendered, even with AJAX calls.I just saw that some types like IntegerChoices (which is of type (int, Choices), and Choices is an Enum) are not supported by Unicorn. But I get no error message or warning, even when logging is set to DEBUG.
I suggest that Enums should be supported...
Beta Was this translation helpful? Give feedback.
All reactions