@classmethod<EOL><INDENT>def widget_from_django_field(cls, f, default=widgets.Widget):<DEDENT>
result = default<EOL>internal_type = "<STR_LIT>"<EOL>if callable(getattr(f, "<STR_LIT>", None)):<EOL><INDENT>internal_type = f.get_internal_type()<EOL><DEDENT>if internal_type in cls.WIDGETS_MAP:<EOL><INDENT>result = cls.WIDGETS_MAP[internal_type]<EOL>if isinstance(result, str):<EOL><INDENT>result = getattr(cls, result)(f)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>from django.contrib.postgres.fields import ArrayField, JSONField<EOL><DEDENT>except ImportError:<EOL><INDENT>class ArrayField:<EOL><INDENT>pass<EOL><DEDENT>class JSONField:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if isinstance(f, ArrayField):<EOL><INDENT>return widgets.SimpleArrayWidget<EOL><DEDENT>elif isinstance(f, JSONField):<EOL><INDENT>return widgets.JSONWidget<EOL><DEDENT><DEDENT>return result<EOL>
Returns the widget that would likely be associated with each
Django type.

Includes mapping of Postgres Array and JSON fields. In the case that
psycopg2 is not installed, we consume the error and process the field
regardless.