Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unicodecsv
- from anomali.apps.categories.models import Category
- with open('/home/imamasari/menu.csv', 'rb') as csv_file:
- field = unicodecsv.reader(csv_file)
- for row in field:
- row = [field.strip() for field in row]
- col1, col2, col3, = row
- if not col1:
- continue
- if col1 == "Category :":
- category = Category.objects.create(name=col2)
- continue
- price_regular = float(col2) if col2 else 0
- price_large = float(col3) if col3 else 0
- category.products.create(
- name=col1, price_regular=price_regular,
- price_large=price_large)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement