def start_element_mit(name, attrs): from mitdining.models import Category, MenuItem, Store, OptionPrice, StoreCategory global current_category, current_store print 'Start element:', name, attrs if name == 'item': # store menu item detail = option_prices(attrs['price']) if 'market' in attrs['price'].lower(): m = MenuItem(name=attrs['name'], price=-1, description=attrs['description'], category=current_category) m.save() elif len(detail)>1: m = MenuItem(name=attrs['name'], price=-2, description=attrs['description'], category=current_category) m.save() o = OptionPrice(item=m, option_one=detail[0], price_one=detail[1], option_two=detail[2], price_two=detail[3]) o.save() else: m = MenuItem(name=attrs['name'], price=strip_dollar(attrs['price']), description=attrs['description'], category=current_category) m.save() elif name == 'category': # category # create category c = Category(name=attrs['name']) if 'description' in attrs: c.description=attrs['description'] c.store = current_store c.save() current_category = c elif name == 'menu': s = Store(name=attrs['store'], store_category=StoreCategory.objects.get(name='House Dining')) s.save() current_store = s
import restaurant from legals.models import Store, Category, MenuItem, OptionPrice s = restaurant.models.Store.objects.get(id=1) s_new = Store(name=s.name, address=s.address, city=s.city, state=s.state, phone=s.phone) s_new.save() cats = restaurant.models.Category.objects.filter(store=s) for c in cats: newc = Category(name=c.name, description=c.description) newc.save() # get old items items = c.menuitem_set.all() for i in items: # create new items m = MenuItem(name=i.name, price=i.price, description=i.description, category=newc) m.save() # if it has multiple price if i.price == -2: p = i.optionprice_set.all()[0] o = OptionPrice(item=m, option_one=p.option_one, price_one=p.price_one, option_two=p.option_two, price_two=p.price_two) o.save()
m.save() try: m = MenuItem.objects.get(name="Cherrystone Twelve Raw Clams") m.name = "Cherrystone Raw Clams" m.price = -2 m.save() except MenuItem.DoesNotExist: m = MenuItem.objects.get(name="Cherrystone Raw Clams") m.price = -2 m.save() try: OptionPrice.objects.get(item=m) except OptionPrice.DoesNotExist: o = OptionPrice(item=m, option_one="six", price_one=6.95, option_two="twelve", price_two=11.95) o.save() m = MenuItem.objects.get(name="Littleneck Raw Clams") o = OptionPrice.objects.get(item=m) o.price_two = 11.95 o.save() m = MenuItem.objects.get(name="Jumbo Shrimp Cocktail") m.price = 13.95 m.save() m = MenuItem.objects.get(name="Smoked Salmon") m.price = 12.50 m.save()