diff --git a/simple_locations/base_models.py b/simple_locations/base_models.py index e9f920d..ac61a0b 100644 --- a/simple_locations/base_models.py +++ b/simple_locations/base_models.py @@ -35,20 +35,23 @@ class Meta: def __str__(self): return _("%(lat)s, %(lon)s") % {"lat": self.latitude, "lon": self.longitude} -Meta = type('Meta', (object,), {'abstract': True}) + +Meta = type("Meta", (object,), {"abstract": True}) + def get_area_base(kind_model: AbstractBaseAreaType, point_model: AbstractBasePoint): """Return the AbstractBaseArea base class - kind_model: Concrete Model for Area Type - point_model: Concrete Model for Point + kind_model: Concrete Model for Area Type + point_model: Concrete Model for Point """ attrs = { - 'kind': models.ForeignKey(kind_model, blank=True, null=True, on_delete=models.CASCADE), - 'location': models.ForeignKey(point_model, blank=True, null=True, on_delete=models.CASCADE), - '__module__': __name__, - 'Meta': Meta(), + "kind": models.ForeignKey(kind_model, blank=True, null=True, on_delete=models.CASCADE), + "location": models.ForeignKey(point_model, blank=True, null=True, on_delete=models.CASCADE), + "__module__": __name__, + "Meta": Meta(), } - return type('AbstractBaseArea', (_AbstractBaseArea,), attrs) + return type("AbstractBaseArea", (_AbstractBaseArea,), attrs) + class _AbstractBaseArea(MPTTModel): class Meta: @@ -110,14 +113,15 @@ def __str__(self) -> str: def get_projected_area_base(area_model: _AbstractBaseArea): """Return the AbstractBaseProjectedArea base class - area_model: Concrete Model for Area + area_model: Concrete Model for Area """ attrs = { - 'area': models.OneToOneField(area_model, primary_key=True, on_delete=models.CASCADE), - '__module__': __name__, - 'Meta': Meta(), + "area": models.OneToOneField(area_model, primary_key=True, on_delete=models.CASCADE), + "__module__": __name__, + "Meta": Meta(), } - return type('AbstractBaseProjectedArea', (_AbstractBaseProjectedArea,), attrs) + return type("AbstractBaseProjectedArea", (_AbstractBaseProjectedArea,), attrs) + class _AbstractBaseProjectedArea(models.Model): """ @@ -132,16 +136,18 @@ class Meta: geom = MultiPolygonField(null=True, blank=True, srid=3857) + def get_border_base(area_model: _AbstractBaseArea): """Return the AbstractBaseProjectedArea base class - area_model: Concrete Model for Area + area_model: Concrete Model for Area """ attrs = { - 'area': models.ManyToManyField(area_model), - '__module__': __name__, - 'Meta': Meta(), + "area": models.ManyToManyField(area_model), + "__module__": __name__, + "Meta": Meta(), } - return type('AbstractBaseBorder', (_AbstractBaseBorder,), attrs) + return type("AbstractBaseBorder", (_AbstractBaseBorder,), attrs) + class _AbstractBaseBorder(models.Model): """ diff --git a/simple_locations/models.py b/simple_locations/models.py index e649d9f..bb7a137 100644 --- a/simple_locations/models.py +++ b/simple_locations/models.py @@ -81,15 +81,17 @@ class Point(base_models.AbstractBasePoint): class Meta(base_models.AbstractBasePoint.Meta): app_label = "simple_locations" + class AreaType(base_models.AbstractBaseAreaType): class Meta(base_models.AbstractBaseAreaType.Meta): app_label = "simple_locations" -class Area(base_models.get_area_base(AreaType, Point)): +class Area(base_models.get_area_base(AreaType, Point)): class Meta(base_models._AbstractBaseArea.Meta): app_label = "simple_locations" + class ProjectedArea(base_models.get_projected_area_base(Area)): pass diff --git a/sl_tests/models.py b/sl_tests/models.py index 8a44de5..417fccb 100644 --- a/sl_tests/models.py +++ b/sl_tests/models.py @@ -6,4 +6,4 @@ class WgsPoint(models.Model): class MercatorPoint(models.Model): - position = models.PointField(srid=3857) \ No newline at end of file + position = models.PointField(srid=3857)