def _save_members(self, artist, metadata): for d in metadata.get('members', []): member_metadata = Discogs.get_resource(d['resource_url']) try: member = Artist.objects.get(discogs_id=int(d['id'])) except Artist.DoesNotExist: member = Artist.objects.create(discogs_id=int(d['id']), name=d['name']) member_metadata = self._save_images(member, member_metadata) member.about = member_metadata.get('profile') member_metadata = self._remove_metadata_keys(member_metadata) member.set_metadata_object(member_metadata) member.save() ArtistMembership.objects.create(artist=artist, member=member, active=d['active']) artist.save() metadata = self._remove_metadata_keys(metadata) return metadata
def save(self): data = self.cleaned_data new = True metadata = Discogs.get_resource(data['resource_url']) try: artist = Artist.objects.get(discogs_id=metadata['id']) new = False except Artist.DoesNotExist: artist = Artist.objects.create(discogs_id=metadata['id'], name=metadata['name'], about=metadata.get('profile')) self.is_new = new if not new: return artist metadata = self._save_images(artist, metadata) metadata = self._save_members(artist, metadata) artist.set_metadata_object(metadata) artist.save() return artist