Exemple #1
0
def restaurantDetails(request):
    data = {'title': 'My Restaurant Details'}
    print("one")
    if request.method == "POST":
        name = request.POST.get('name')
        address1 = request.POST.get('address1', '')
        address2 = request.POST.get('address2', '')
        country = request.POST.get('country', 'India')
        state = request.POST.get('state', '')
        zip = request.POST.get('zip', '')
        location = request.POST.get('location', 'pala')
        tag = request.POST.get('tag', '')
        if not name:
            messages.error(request, 'cant save restaurant details')
            return redirect('restaurant_details')
        rest = Restaurant()
        try:
            rest = Restaurant.objects.create(user=request.user,
                                             name=name,
                                             address1=address1,
                                             address2=address2,
                                             country=country,
                                             state=state,
                                             zip=zip,
                                             location=location,
                                             tag=tag)
            messages.info(request, 'saved restaurant details')

        except IntegrityError:
            rest = Restaurant.objects.get(user=request.user)
            rest.name = name
            rest.address1 = address1
            rest.address2 = address2
            rest.country = country
            rest.state = state
            rest.zip = zip
            rest.location = location
            rest.tag = tag
            rest.save()
            messages.info(request, 'updated restaurant details.')
        except:
            messages.info(request, 'cant save restaurant details. try again')

        return redirect('restaurant_details')

    data['rest'] = Restaurant.objects.filter(
        user=request.user).order_by('id').first()
    print(data['rest'])
    return render(request, 'partner/owner/restaurant_details.html',
                  processData(request, data))
Exemple #2
0
def restaurantDetails(request):
    data = {'title': 'My Restaurant Details'}
    print("one")
    if request.method == "POST":
        name = request.POST.get('name')
        address1 = request.POST.get('address1', '')
        address2 = request.POST.get('address2', '')
        zip = request.POST.get('zip', '')
        tag = request.POST.get('tag', '')
        if not name:
            messages.error(request, 'cant save restaurant details')
            return redirect('restaurant_details')
        rest = Restaurant()
        try:
            rest = Restaurant.objects.create(user=request.user,
                                             name=name,
                                             address1=address1,
                                             address2=address2,
                                             zip=zip,
                                             tag=tag)
            messages.info(request, 'saved restaurant details')

        except IntegrityError:  #this error is generated on the loss of uniqueness of the assumed unique variable user
            rest = Restaurant.objects.get(user=request.user)
            rest.name = name
            rest.address1 = address1
            rest.address2 = address2
            rest.zip = zip
            rest.tag = tag
            rest.save()
            messages.info(request, 'updated restaurant details.')
        except:
            messages.info(
                request,
                'Loss of uniquness. Cant save restaurant details. Try again')

        return redirect('restaurant_details')

    data['rest'] = Restaurant.objects.filter(
        user=request.user).order_by('id').first()
    print(data['rest'])
    return render(request, 'partner/owner/restaurant_details.html',
                  processData(request, data))