mbourqui / django-echoices Goto Github PK
View Code? Open in Web Editor NEWDjango model choices as Enum
License: MIT License
Django model choices as Enum
License: MIT License
To print the value
and label
of the EChoice
Set internal type to EChoiceField
.
Most of Python's libraries are BSD/MIT licensed for a reason: we can freely use each others code.
This project is GPLv3 licensed, meaning any project that uses this library MUST published under GPLv3 too. I also have to open all my website and application sources by using this library. Is this wat you consciously intended, or was that an accidental mistake?
Since we're the only copyright holders of this project, you can still freely change the license if you wish.
To support the additional label
attribute.
This should allow to define EChoices on the fly.
Occurs when wanting to manually add a new object through the admin (while accessing someobject/add/
).
Traceback (most recent call last):
[...]
File "/usr/local/lib/python3.5/site-packages/django/template/defaulttags.py", line 315, in render
return nodelist.render(context)
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 994, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 961, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.5/site-packages/django/template/defaulttags.py", line 315, in render
return nodelist.render(context)
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 994, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 961, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 1044, in render
output = self.filter_expression.resolve(context)
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 711, in resolve
obj = self.var.resolve(context)
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 852, in resolve
value = self._resolve_lookup(context)
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 915, in _resolve_lookup
current = current()
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/helpers.py", line 227, in contents
result_repr = display_for_field(value, f, self.empty_value_display)
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/utils.py", line 387, in display_for_field
return dict(field.flatchoices).get(value, empty_value_display)
TypeError: unhashable type: 'EOrderedChoice'
__call__
__getattr__
__setattr__
The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.
The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.
When displaying a form field with initial data (like in the admin), the EChoice is not selected.
When using an IntegerField, a validation is made that requires integer comparison. But comparison with non-EOrderedChoices is not yet supported.
Support multiple selection using django-multiselectfield
merge CharEChoiceField and IntegerEChoiceField
The value/label of the EChoice is not shown, but '-' instead.
Potential Traceback:
[...]
File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 852, in resolve
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/helpers.py", line 227, in contents
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/utils.py", line 387, in display_for_field
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if getattr(field, 'flatchoices', None):
return dict(field.flatchoices).get(value, empty_value_display)
where
value = <EChoice.NAME: value>
field = <echoices.fields.EChoiceField: field_name>
field.flatchoices = [(value, 'label')]
empty_value_display = django.utils.safestring.SafeText('-')
Traceback (most recent call last):
[...]
File "/usr/local/lib/python3.5/site-packages/django/forms/forms.py", line 169, in is_valid
return self.is_bound and not self.errors
File "/usr/local/lib/python3.5/site-packages/django/forms/forms.py", line 161, in errors
self.full_clean()
File "/usr/local/lib/python3.5/site-packages/django/forms/forms.py", line 372, in full_clean
self._post_clean()
File "/usr/local/lib/python3.5/site-packages/django/forms/models.py", line 398, in _post_clean
self.instance.full_clean(exclude=exclude, validate_unique=False)
File "/usr/local/lib/python3.5/site-packages/django/db/models/base.py", line 1210, in full_clean
self.clean_fields(exclude=exclude)
File "/usr/local/lib/python3.5/site-packages/django/db/models/base.py", line 1252, in clean_fields
setattr(self, f.attname, f.clean(raw_value, self))
File "/usr/local/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 592, in clean
self.run_validators(value)
File "/usr/local/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 538, in run_validators
if value in self.empty_values:
File "/usr/local/lib/python3.5/site-packages/echoices/enums.py", line 252, in __eq__
return self.value == self.coerce(other)
File "/usr/local/lib/python3.5/site-packages/echoices/enums.py", line 231, in coerce
return cls.__value_type_(other)
ValueError: invalid literal for int() with base 10: ''
File "/usr/local/lib/python3.5/site-packages/echoices/fields.py" in get_prep_value
63. return value.value
Exception Type: AttributeError at /admin/publications_bootstrap/publication/
Exception Value: 'str' object has no attribute 'value'
Actually, usgin a form generates the following error:
Select a valid choice. EChoice.FIELD is not one of the available choices.
As found here:
https://github.com/5monkeys/django-enumfield
Either all strings or all ints
Traceback (most recent call last):
[...]
File "/usr/local/lib/python3.5/site-packages/django/forms/forms.py", line 169, in is_valid
return self.is_bound and not self.errors
File "/usr/local/lib/python3.5/site-packages/django/forms/forms.py", line 161, in errors
self.full_clean()
File "/usr/local/lib/python3.5/site-packages/django/forms/forms.py", line 372, in full_clean
self._post_clean()
File "/usr/local/lib/python3.5/site-packages/django/forms/models.py", line 398, in _post_clean
self.instance.full_clean(exclude=exclude, validate_unique=False)
File "/usr/local/lib/python3.5/site-packages/django/db/models/base.py", line 1210, in full_clean
self.clean_fields(exclude=exclude)
File "/usr/local/lib/python3.5/site-packages/django/db/models/base.py", line 1252, in clean_fields
setattr(self, f.attname, f.clean(raw_value, self))
File "/usr/local/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 592, in clean
self.run_validators(value)
File "/usr/local/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 538, in run_validators
if value in self.empty_values:
File "/usr/local/lib/python3.5/site-packages/echoices/enums.py", line 251, in __eq__
return self.value == self.coerce(other)
File "/usr/local/lib/python3.5/site-packages/echoices/enums.py", line 231, in coerce
return cls.__value_type_(other)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Comparators can not be used, as they apply on the EChoice instance instead of the label, for example when using an IntegerField.
Occurs if the value of the EChoice is not a string.
Similar to CharEChoiceField.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.