blechreiz-website/location_field/models.py

40 lines
1.2 KiB
Python
Raw Permalink Normal View History

from django.db.models import CharField
from location_field import forms
class BaseLocationField(object):
2013-09-27 11:39:28 +02:00
def __init__(self, based_field=None, zoom=2, default=None, *args, **kwargs):
self._based_field = based_field
self._zoom = zoom
self._default = default
self.default = default
def formfield(self, **kwargs):
return super(BaseLocationField, self).formfield(
form_class=self.formfield_class,
2013-09-27 11:39:28 +02:00
based_field=self._based_field,
zoom=self._zoom,
default=self._default,
**kwargs)
class PlainLocationField(BaseLocationField, CharField):
formfield_class = forms.PlainLocationField
2013-09-27 11:39:28 +02:00
def __init__(self, based_field=None, zoom=None,
max_length=63, *args, **kwargs):
2013-09-27 11:39:28 +02:00
super(PlainLocationField, self).__init__(based_field=based_field,
zoom=zoom, *args, **kwargs)
CharField.__init__(self, max_length=max_length, *args, **kwargs)
# south compatibility
try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^location_field\.models\.PlainLocationField"])
except:
pass