Skip to content

Commit

Permalink
feat: fixed bug in removing old coordinates associated with a boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-hd committed Nov 27, 2023
1 parent e121afa commit 76a4776
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions communities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ def registration_boundaries(request):
community.source_of_boundaries = post_data['source']
community.name_of_boundaries = post_data['name']

# remove old boundaries
community.boundaries.clear()
# remove all coordinates for (all boundaries in this community)
Coordinate.objects.filter(coordinates__boundaries__id=community.id).delete()

# remove all boundaries in this community
community.boundaries.all().delete()

# add new boundaries in this community
for coordinates in post_data['boundaries']:
coordinates = [
Coordinate.objects.create(latitude=lat, longitude=lon)
for lat, lon in coordinates
]
boundary = Boundary.objects.create()
boundary.coordinates.set(coordinates)
for lat, lon in coordinates:
boundary.coordinates.add(
Coordinate.objects.create(latitude=lat, longitude=lon)
)
community.boundaries.add(boundary)
community.save()

Expand Down

0 comments on commit 76a4776

Please sign in to comment.