又是我.
当用户登录时,我似乎仍然无法显示我的用户预订.我知道这可能是一些超基本的东西,但我只是没有看到它.
提前感谢您提供的任何帮助.
HTML:
{% extends "base.html" %}
{% block content %}
<section id="booking" class="book_a_table">
<div class="booking_container">
<h2>My Bookings:</h2>
<p>To edit or cancel a booking please click on the buttons below.</p>
<div class="row">
<div class="col-md-3 mt-5 offset-md-3">
{% for booking in bookings %}
<div class="col-md-4">
<div class="card mb-4">
<div class="card-body">
<h4 class='card-title text-uppercase text-center'>{{ booking.date }} at
{{ booking.time }}</h4>
<h6 class="text-uppercase">{{ booking.name }}</h6>
<div class='card-text'>
<p><i class="fas fa-phone"></i> {{ booking.phone }}</p>
<p><i class="far fa-envelope"></i> {{ booking.email }}</p>
<p>Number of People: {{ booking.number_of_people }}</p>
{%endfor%}
</div>
</div>
</div>
</section>
看法py:
class ListBookingView(generic.ListView):
"""
This is the view that will bring up the
list of bookings for a particular users
so that they can be edited or deleted
"""
model = Booking
template_name = 'my_bookings.html'
def get(self, request, *args, **kwargs):
if request.user.is_authenticated:
booking = Booking.objects.filter(user=request.user)
my_bookings = filter(self, booking)
return render(request, 'my_bookings.html', {
'my_bookings': my_bookings
}
)
else:
return redirect('account_login')