Skip to content

Commit

Permalink
Make artist xml import update and fix sname length bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavAndreasson committed Feb 9, 2024
1 parent 18033a2 commit 0bbb97a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions records/management/commands/readartistxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ def handle(self, *args, **options):
and not elem.find("data_quality").text in ("Needs Major Changes", "Entirely Incorrect")
):
name = elem.find("name").text
sname = name[:20].lower()
sname = name.lower()[:20]
artists_batch.append(Artist(id=elem.find("id").text, name=name, sname=sname))
if len(artists_batch) >= batch_size:
Artist.objects.bulk_create(artists_batch, ignore_conflicts=True)
Artist.objects.bulk_create(
artists_batch, update_conflicts=True, update_fields=("name", "sname")
)
artists_batch = []
artists_imported += batch_size
artist_counter += 1
Expand All @@ -67,6 +69,8 @@ def handle(self, *args, **options):
if loop_counter > end:
break
if artists_batch:
Artist.objects.bulk_create(artists_batch, ignore_conflicts=True)
Artist.objects.bulk_create(
artists_batch, ignore_conflicts=True, update_conflicts=True, update_fields=("name", "sname")
)
artists_imported += len(artists_batch)
self.stdout.write("\nArtist import done. " + str(artists_imported) + " artists imported.")
2 changes: 1 addition & 1 deletion records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def to_dict(self, full=True):
}

def save(self, *args, **kwargs):
self.sname = self.name[:20].lower()
self.sname = self.name.lower()[:20]
super(Artist, self).save(*args, **kwargs)

class Meta:
Expand Down

0 comments on commit 0bbb97a

Please sign in to comment.