-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#9] Provide Mixin to retrieve field choices dynamically
- Loading branch information
Showing
3 changed files
with
127 additions
and
100 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from .models import OpenFormsSlugField, OpenFormsUUIDField | ||
|
||
|
||
class OpenFormsClientMixin: | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
# retrieve choices for OpenForms fields when the form instance is created | ||
form_fields = self.instance._meta.fields | ||
openforms_fields = ( | ||
field | ||
for field in form_fields | ||
if isinstance(field, (OpenFormsSlugField, OpenFormsUUIDField)) | ||
) | ||
for field in openforms_fields: | ||
field.choices = field.get_choices(include_blank=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters