Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bryan BRANCOTTE
django-basetheme-bootstrap
Commits
052026e3
Commit
052026e3
authored
Jul 16, 2021
by
Bryan BRANCOTTE
Browse files
automatically use CheckboxSelectMultiple for M2M
parent
af906a75
Changes
1
Hide whitespace changes
Inline
Side-by-side
basetheme_bootstrap/views.py
View file @
052026e3
...
...
@@ -223,15 +223,19 @@ def account_detail(request):
else
:
is_posted
=
request
.
method
==
'POST'
pref
=
klass
.
get_for_user
(
user
=
request
.
user
)
widgets_dict
=
dict
(
(
f
.
name
,
widgets
.
CheckboxSelectMultiple
())
for
f
in
pref
.
_meta
.
get_fields
()
if
f
.
many_to_many
)
form_prefs
=
forms
.
modelform_factory
(
klass
,
fields
=
list
(
klass
.
get_allowed_fields
()),
fields
=
list
(
pref
.
get_allowed_fields
()),
widgets
=
widgets_dict
,
)(
instance
=
pref
,
data
=
request
.
POST
if
is_posted
else
None
)
if
is_posted
and
form_prefs
.
is_valid
():
form_prefs
.
save
()
form_prefs
=
forms
.
modelform_factory
(
klass
,
fields
=
list
(
klass
.
get_allowed_fields
()),
fields
=
list
(
pref
.
get_allowed_fields
()),
widgets
=
widgets_dict
,
)(
instance
=
klass
.
get_for_user
(
user
=
request
.
user
))
# dirty patch for time field (don't know why django doesn't express the correct type by default)
for
f
in
form_prefs
.
fields
.
values
():
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment