def resto_edit(request, pk=None): instance = get_object_or_404(Restaurant, id=pk) resto = instance form = RestaurantEditForm(None, instance=instance) menu_form = MenuEditForm() menu_form.restaurant = instance contact = Contact.objects.get(restaurant=resto) contact_form = ContactForm(None, instance=contact) address_form = AddressForm(None, instance=Address.objects.get(restaurant=instance)) context_dict = {"resto": instance, "form": form, "menu_form": menu_form, "menus": ({"name": m.menu_name, "pk": m.pk} for m in Menu.objects.filter(restaurant=instance)), "gallery": Gallery.objects.filter(restaurant=instance), "contact_form": contact_form, "address_form": address_form } context_dict.update(csrf(request)) return render_to_response('organizer/restaurant_edit.html', context_dict, context_instance=RequestContext(request))
def resto_validate(request): if request.method == 'POST': restaurant = Restaurant.objects.get(id=request.POST['restaurant']) restaurant_form = RestaurantEditForm(request.POST, instance=restaurant) if restaurant_form.is_valid(): restaurant_form.save() menu = Menu.objects.get(id=request.POST['menu']) if request.POST['menu'] else None menu_form = MenuEditForm(request.POST, instance=menu) if menu_form.is_valid(): menu_form.save() contact_form = ContactForm(request.POST, instance=Contact.objects.get(restaurant=restaurant)) if contact_form.is_valid(): contact_form.save() address_form = AddressForm(request.POST, instance=Address.objects.get(restaurant=restaurant)) if address_form.is_valid(): address_form.save() return HttpResponseRedirect(reverse_lazy('resto-list'))