def profile_create(request): form = ProfileForm(request.POST) form.instance.user = request.user if form.is_valid(): form.save() return redirect(reverse('user_profile')) else: context = {'title': 'Profile', 'form': form} return render(request, 'profile.html', context)
def profile(request): user_reservation = request.user reserv = user_reservation.reserved_restaurants.all() for res in reserv: no_of_total_visits = Reservation.objects.filter( user=user_reservation, restaurant=res).count() visits_in_last_6 = Reservation.objects.filter( user=user_reservation, restaurant=res).filter(date__gte=datetime.now() - timedelta(180)).count() if no_of_total_visits > 7 or visits_in_last_6 > 2: res.fav = True else: res.fav = False # for user_reservation in reserv.user: # no_of_total_visits = Reservation.objects.filter(user = user_reservation, restaurant = restaurants).count() # visits_in_last_6 = Reservation.objects.filter(user = user_reservation, restaurant = restaurants).filter(date__gte= datetime.now() - timedelta(180)).count() # if no_of_total_visits > 7 or visits_in_last_6 > 2: # user_reservation.vip_user = True # else: # user_reservation.vip_user = False context = {'title': 'Profile', 'reserv': set(reserv)} if not Profile.exists_for_user(request.user): form = ProfileForm() context['form'] = form return render(request, 'profile.html', context)
def profile(request): context = {'title': 'Profile'} if not Profile.exists_for_user(request.user): form = ProfileForm() context['form'] = form return render(request, 'profile.html', context)