# 139 Parcel reference improved
* improves frontend layout to display more details on district, municipal and parce group * improves ordering of parcels * refactors parcel related models * improves parcel fetching * extends and simplifies sanitize_db parcel related code
This commit is contained in:
@@ -99,7 +99,7 @@ class Geometry(BaseResource):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
from konova.models import Parcel, District, ParcelIntersection
|
||||
from konova.models import Parcel, District, ParcelIntersection, Municipal, ParcelGroup
|
||||
parcel_fetcher = ParcelWFSFetcher(
|
||||
geometry_id=self.id,
|
||||
)
|
||||
@@ -115,16 +115,28 @@ class Geometry(BaseResource):
|
||||
# which needs to be deleted and just keep the numerical values
|
||||
## THIS CAN BE REMOVED IN THE FUTURE, WHEN 'Flur' WON'T OCCUR ANYMORE!
|
||||
flr_val = fetched_parcel["ave:flur"].replace("Flur ", "")
|
||||
district = District.objects.get_or_create(
|
||||
key=fetched_parcel["ave:kreisschl"],
|
||||
name=fetched_parcel["ave:kreis"],
|
||||
)[0]
|
||||
municipal = Municipal.objects.get_or_create(
|
||||
key=fetched_parcel["ave:gmdschl"],
|
||||
name=fetched_parcel["ave:gemeinde"],
|
||||
district=district,
|
||||
)[0]
|
||||
parcel_group = ParcelGroup.objects.get_or_create(
|
||||
key=fetched_parcel["ave:gemaschl"],
|
||||
name=fetched_parcel["ave:gemarkung"],
|
||||
municipal=municipal,
|
||||
)[0]
|
||||
parcel_obj = Parcel.objects.get_or_create(
|
||||
gmrkng=fetched_parcel["ave:gemarkung"],
|
||||
district=district,
|
||||
municipal=municipal,
|
||||
parcel_group=parcel_group,
|
||||
flr=flr_val,
|
||||
flrstck_nnr=fetched_parcel['ave:flstnrnen'],
|
||||
flrstck_zhlr=fetched_parcel['ave:flstnrzae'],
|
||||
)[0]
|
||||
district = District.objects.get_or_create(
|
||||
gmnd=fetched_parcel["ave:gemeinde"],
|
||||
krs=fetched_parcel["ave:kreis"],
|
||||
)[0]
|
||||
parcel_obj.district = district
|
||||
parcel_obj.updated_on = _now
|
||||
parcel_obj.save()
|
||||
@@ -155,9 +167,10 @@ class Geometry(BaseResource):
|
||||
parcels = self.parcels.filter(
|
||||
parcelintersection__calculated_on__isnull=False,
|
||||
).prefetch_related(
|
||||
"district"
|
||||
"district",
|
||||
"municipal",
|
||||
).order_by(
|
||||
"gmrkng",
|
||||
"municipal__name",
|
||||
)
|
||||
|
||||
return parcels
|
||||
|
||||
@@ -10,8 +10,64 @@ from django.db import models
|
||||
from konova.models import UuidModel
|
||||
|
||||
|
||||
class AdministrativeSpatialReference(models.Model):
|
||||
key = models.CharField(
|
||||
max_length=255,
|
||||
help_text="Represents Kreisschlüssel",
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
name = models.CharField(
|
||||
max_length=1000,
|
||||
help_text="Kreis",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.key})"
|
||||
|
||||
@property
|
||||
def table_str(self):
|
||||
return f"{self.name} ({self.key})"
|
||||
|
||||
|
||||
class District(UuidModel, AdministrativeSpatialReference):
|
||||
""" The model District refers to "Kreis"
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class Municipal(UuidModel, AdministrativeSpatialReference):
|
||||
""" The model Municipal refers to "Gemeinde"
|
||||
|
||||
"""
|
||||
district = models.ForeignKey(
|
||||
District,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
|
||||
class ParcelGroup(UuidModel, AdministrativeSpatialReference):
|
||||
""" The model ParcelGroup refers to "Gemarkung", which is defined as a loose group of parcels
|
||||
|
||||
"""
|
||||
municipal = models.ForeignKey(
|
||||
Municipal,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
|
||||
class Parcel(UuidModel):
|
||||
""" The Parcel model holds administrative data on the covered properties.
|
||||
""" The Parcel model holds administrative data on covered properties.
|
||||
|
||||
Due to the unique but relevant naming of the administrative data, we have to use these namings as field
|
||||
names in german. Any try to translate them to English result in strange or insufficient translations.
|
||||
@@ -24,59 +80,34 @@ class Parcel(UuidModel):
|
||||
"""
|
||||
geometries = models.ManyToManyField("konova.Geometry", blank=True, related_name="parcels", through='ParcelIntersection')
|
||||
district = models.ForeignKey("konova.District", on_delete=models.SET_NULL, null=True, blank=True, related_name="parcels")
|
||||
gmrkng = models.CharField(
|
||||
max_length=1000,
|
||||
municipal = models.ForeignKey("konova.Municipal", on_delete=models.SET_NULL, null=True, blank=True, related_name="parcels")
|
||||
parcel_group = models.ForeignKey(
|
||||
"konova.ParcelGroup",
|
||||
on_delete=models.SET_NULL,
|
||||
help_text="Gemarkung",
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="parcels"
|
||||
)
|
||||
flrstck_nnr = models.CharField(
|
||||
max_length=1000,
|
||||
flr = models.IntegerField(
|
||||
help_text="Flur",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
flrstck_nnr = models.IntegerField(
|
||||
help_text="Flurstücksnenner",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
flrstck_zhlr = models.CharField(
|
||||
max_length=1000,
|
||||
flrstck_zhlr = models.IntegerField(
|
||||
help_text="Flurstückszähler",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
flr = models.CharField(
|
||||
max_length=1000,
|
||||
help_text="Flur",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
updated_on = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.gmrkng} | {self.flr} | {self.flrstck_zhlr} | {self.flrstck_nnr}"
|
||||
|
||||
|
||||
class District(UuidModel):
|
||||
""" The model District holds more coarse information, such as Kreis, Verbandsgemeinde and Gemeinde.
|
||||
|
||||
There might be the case that a geometry lies on a hundred Parcel entries but only on one District entry.
|
||||
Therefore a geometry can have a lot of relations to Parcel entries but only a few or only a single one to one
|
||||
District.
|
||||
|
||||
"""
|
||||
gmnd = models.CharField(
|
||||
max_length=1000,
|
||||
help_text="Gemeinde",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
krs = models.CharField(
|
||||
max_length=1000,
|
||||
help_text="Kreis",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.gmnd} | {self.krs}"
|
||||
return f"{self.parcel_group} | {self.flr} | {self.flrstck_zhlr} | {self.flrstck_nnr}"
|
||||
|
||||
|
||||
class ParcelIntersection(UuidModel):
|
||||
|
||||
Reference in New Issue
Block a user