def save(request, object_id=None): if object_id: object = get_object_or_404( Place, pk=object_id, organization=request.user.get_profile().org_active) else: object = Place() try: object.visible = get_visible(request, request.POST['visible']) except: object.visible = False # all others place will be filial if place_type of object is Matriz if request.POST.get('place_type') == '1': # hardcode for x in Place.objects.filter( organization=request.user.get_profile().org_active, place_type__id=1): # todos que são matriz x.place_type = PlaceType.objects.get(pk=4) # hardcode x.save() object.label = request.POST['label'] object.comments = request.POST.get('comments') object.place_type = PlaceType.objects.get(pk=request.POST['place_type']) object.organization = request.user.get_profile().org_active object.hour_start = request.POST['hour_start'] object.hour_end = request.POST['hour_end'] object.save() phone_save(object, request.POST.getlist('phoneId'), request.POST.getlist('area'), request.POST.getlist('phoneNumber'), request.POST.getlist('ext'), request.POST.getlist('phoneType')) address_save(object, request.POST.getlist('addressId'), request.POST.getlist('addressPrefix'), request.POST.getlist('addressLine1'), request.POST.getlist('addressLine2'), request.POST.getlist('addressNumber'), request.POST.getlist('neighborhood'), request.POST.getlist('zipCode'), request.POST.getlist('addressType'), request.POST.getlist('city'), request.POST.getlist('foreignCountry'), request.POST.getlist('foreignState'), request.POST.getlist('foreignCity')) messages.success(request, _('Place saved successfully')) return HttpResponseRedirect('/place/%s/' % object.id)