[Answered ]-Insert CSV data in django models, empty values

2👍

I’ve googled and it may be even shorter:

year = row[1] or 0

We can close the question.

👤dease

0👍

just give year=int(row[1]) if row[1] else 0

elm, created_elm = Elm.objects.get_or_create(name=row[0], year=int(row[1]) if row[1] else 0, power=int(row[2]))

Leave a comment