Commit 7ea13aa8 authored by Bram's avatar Bram
Browse files

[enh] import_representatives_no_preserve works if representatives aren't in the db already

parent c44b538a
......@@ -23,7 +23,13 @@ class Command(BaseCommand):
sys.stdout.write("%s/%s\r" % (a, end))
sys.stdout.flush()
remote_id = reps["id"]
representative = Representative.objects.get(remote_id=remote_id)
representative = Representative.objects.filter(remote_id=remote_id)
if representative:
representative = representative[0]
else:
representative = Representative()
representative.remote_id = remote_id
representative.first_name = reps["personal"]["first_name"]
representative.last_name = reps["personal"]["last_name"]
representative.full_name = reps["personal"]["full_name"]
......@@ -32,6 +38,8 @@ class Command(BaseCommand):
representative.cv = reps["personal"]["cv"]
representative.gender = reverted_gender_dict[reps["personal"]["gender"]]
representative.save()
representative.email_set.all().delete()
for email in reps["contact"]["emails"]:
representative.email_set.create(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment