Created
March 1, 2018 21:16
-
-
Save linneudm/2a78d5ea82b50b4e76c4eaef358bc5c2 to your computer and use it in GitHub Desktop.
my widgets
This file contains hidden or 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
from .widgets import ModelSelect2MultipleBootstrap, ModelSelect2Bootstrap | |
class ConsultationForm(ModelForm): | |
class Meta: | |
model = Consultation | |
exclude = ['patient', 'bodycirc', 'energycalc', 'skinfold', 'bioimpedance', 'bonediameter', 'biochemical'] | |
widgets = { | |
'patology': ModelSelect2MultipleBootstrap(url='patient:patology_autocomplete'), | |
#'supplement': autocomplete.ModelSelect2Multiple(url='patient:supplement_autocomplete'), | |
#'vitamin': autocomplete.ModelSelect2Multiple(url='patient:vitamin_autocomplete') | |
} | |
ExamFormSet = forms.inlineformset_factory(Consultation, Exam, fields=('description','path'),extra=1) |
This file contains hidden or 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
from dal.widgets import QuerySetSelectMixin | |
from dal_select2.widgets import Select2, Select2Multiple | |
class Select2BootstrapWidgetMixin(object): | |
def build_attrs(self, *args, **kwargs): | |
attrs = super(Select2BootstrapWidgetMixin, self).build_attrs(*args, **kwargs) | |
attrs.setdefault('data-theme', | |
'bootstrap') | |
return attrs | |
class Media: | |
css = { | |
'all': ( | |
'autocomplete_light/vendor/select2/dist/css/select2.css', # The one from dal_select2.widgets.Select2WidgetMixin | |
'css/select2-bootstrap.min.css' # Bootstrap theme itself | |
) | |
} | |
js = ('autocomplete_light/jquery.init.js', | |
'autocomplete_light/autocomplete.init.js', | |
'autocomplete_light/vendor/select2/dist/js/select2.full.js', | |
'autocomplete_light/select2.js', | |
) | |
class ModelSelect2Bootstrap(QuerySetSelectMixin, | |
Select2BootstrapWidgetMixin, | |
Select2): | |
""" | |
Use this instead of ModelSelect2 widget | |
""" | |
autocomplete_function = 'select2' | |
class ModelSelect2MultipleBootstrap(QuerySetSelectMixin, | |
Select2BootstrapWidgetMixin, | |
Select2Multiple): | |
""" | |
Use this instead of ModelSelect2Multiple widget | |
""" | |
autocomplete_function = 'select2' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment