def select2_modelform_meta(model,<EOL>meta_fields=None,<EOL>widgets=None,<EOL>attrs=None,<EOL>**kwargs):
widgets = widgets or {}<EOL>meta_fields = meta_fields or {}<EOL>for field in model._meta.fields:<EOL><INDENT>if isinstance(field, ForeignKey) or field.choices:<EOL><INDENT>widgets.update({field.name: Select2(select2attrs=attrs)})<EOL><DEDENT><DEDENT>for field in model._meta.many_to_many:<EOL><INDENT>widgets.update({field.name: Select2Multiple(select2attrs=attrs)})<EOL><DEDENT>meta_fields.update({<EOL>'<STR_LIT>': model,<EOL>'<STR_LIT>': widgets,<EOL>})<EOL>if '<STR_LIT>' not in kwargs and '<STR_LIT>' not in kwargs:<EOL><INDENT>meta_fields.update({'<STR_LIT>': []})<EOL><DEDENT>meta_fields.update(**kwargs)<EOL>meta = type('<STR_LIT:Meta>', (object,), meta_fields)<EOL>return meta<EOL>
Return `Meta` class with Select2-enabled widgets for fields
with choices (e.g.  ForeignKey, CharField, etc) for use with
ModelForm.

Arguments:
    model - a model class to create `Meta` class for.
    meta_fields - dictionary with `Meta` class fields, for
        example, {'fields': ['id', 'name']}
    attrs - select2 widget attributes (width, for example),
        must be of type `dict`.
    **kwargs - will be merged with meta_fields.