Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

Change values to lowercase before importing to Django

$
0
0

I am using Django Import-Export to import data from an excel(xlsx) file to my Django Models. What I have works but I want it to consider strings with characters that have different cases to be the same. Currently if I have 'Black Sabbath' and 'black sabbath' in a column, the import considers them to be different artists.

Is it possible to change all string values to lowercase during the import process? Or somehow configure Django to consider them the same?

resources.py

class ArtistResource(resources.ModelResource):

    class Meta:
        model = Artist
        import_id_fields = ('artist',)
        skip_unchanged = True

models.py

class Artist(models.Model):
    artist = models.CharField(primary_key=True, unique=True, max_length=30)

    def __str__(self):
        return self.artist

admin.py

class ArtistAdmin(ImportExportActionModelAdmin):
    resource_class = ArtistResource

Viewing all articles
Browse latest Browse all 88854


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>