#86 Parcel-Geometry improvement
* improves the way parcel-geometry relations are stored on the DB
* instead of a numerical sequence we switched to UUID, so no sequence will run out at anytime (new model: ParcelIntersection)
* instead of dropping all M2M relations between parcel and geometry on each calculation, we keep the ones that still exist, drop the ones that do not exist and add new ones (if new ones exist)
This commit is contained in:
+20
-1
@@ -22,7 +22,7 @@ class Parcel(UuidModel):
|
||||
To avoid conflicts due to german Umlaute, the field names are shortened and vocals are dropped.
|
||||
|
||||
"""
|
||||
geometries = models.ManyToManyField("konova.Geometry", related_name="parcels", blank=True)
|
||||
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,
|
||||
@@ -77,3 +77,22 @@ class District(UuidModel):
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.gmnd} | {self.krs}"
|
||||
|
||||
|
||||
class ParcelIntersection(UuidModel):
|
||||
""" ParcelIntersection is an intermediary model, which is used to configure the
|
||||
M2M relation between Parcel and Geometry.
|
||||
|
||||
Based on uuids, we will not have (practically) any problems on outrunning primary keys
|
||||
and extending the model with calculated_on timestamp, we can 'hide' entries while they
|
||||
are being recalculated and keep track on the last time they have been calculated this
|
||||
way.
|
||||
|
||||
Please note: The calculated_on describes when the relation between the Parcel and the Geometry
|
||||
has been established. The updated_on field of Parcel describes when this Parcel has been
|
||||
changed the last time.
|
||||
|
||||
"""
|
||||
parcel = models.ForeignKey(Parcel, on_delete=models.CASCADE)
|
||||
geometry = models.ForeignKey("konova.Geometry", on_delete=models.CASCADE)
|
||||
calculated_on = models.DateTimeField(auto_now_add=True, null=True, blank=True)
|
||||
|
||||
Reference in New Issue
Block a user