Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import unicodecsv
  2.  
  3. from anomali.apps.categories.models import Category
  4.  
  5. with open('/home/imamasari/menu.csv', 'rb') as csv_file:
  6. field = unicodecsv.reader(csv_file)
  7. for row in field:
  8. row = [field.strip() for field in row]
  9. col1, col2, col3, = row
  10.  
  11. if not col1:
  12. continue
  13.  
  14. if col1 == "Category :":
  15. category = Category.objects.create(name=col2)
  16. continue
  17.  
  18. price_regular = float(col2) if col2 else 0
  19. price_large = float(col3) if col3 else 0
  20. category.products.create(
  21. name=col1, price_regular=price_regular,
  22. price_large=price_large)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement