24 lines
880 B
Python
24 lines
880 B
Python
from django.forms import fields
|
|
|
|
from .widgets import LocationWidget
|
|
|
|
|
|
class PlainLocationField(fields.CharField):
|
|
"""A form field for entering location data with a map widget."""
|
|
|
|
def __init__(self, based_field=None, zoom=None, default=None, *args, **kwargs):
|
|
kwargs["initial"] = default
|
|
self.widget = LocationWidget(based_field=based_field, zoom=zoom, **kwargs)
|
|
|
|
# Extract only the valid kwargs for CharField
|
|
field_kwargs = {
|
|
"required": kwargs.get("required", True),
|
|
"label": kwargs.get("label", None),
|
|
"initial": kwargs.get("initial", None),
|
|
"help_text": kwargs.get("help_text", None),
|
|
"error_messages": kwargs.get("error_messages", None),
|
|
"show_hidden_initial": kwargs.get("show_hidden_initial", False),
|
|
}
|
|
|
|
super().__init__(*args, **field_kwargs)
|