forked from DGNum/gestioCOF
Remove duplicate locations
This commit is contained in:
parent
8a751e5c85
commit
cacdde3f87
1 changed files with 3 additions and 3 deletions
|
@ -22,12 +22,12 @@ def import_events(apps, schema_editor):
|
||||||
# in this table for each value of the old `location` field.
|
# in this table for each value of the old `location` field.
|
||||||
OldEvent, NewEvent = models[0]
|
OldEvent, NewEvent = models[0]
|
||||||
Location = apps.get_model("gestion", "Location")
|
Location = apps.get_model("gestion", "Location")
|
||||||
locations = []
|
locations = set() # A set to prevent duplicate entries
|
||||||
events = []
|
events = []
|
||||||
for event in OldEvent.objects.values():
|
for event in OldEvent.objects.values():
|
||||||
locations.append(Location(name=event["location"]))
|
locations.add(event["location"])
|
||||||
events.append(event)
|
events.append(event)
|
||||||
Location.objects.bulk_create(locations)
|
Location.objects.bulk_create([Location(name=name) for name in locations])
|
||||||
map_loc = {
|
map_loc = {
|
||||||
loc.name: loc
|
loc.name: loc
|
||||||
for loc in Location.objects.all()
|
for loc in Location.objects.all()
|
||||||
|
|
Loading…
Reference in a new issue