koszyk done

This commit is contained in:
Mikhail Ronchyk 2022-01-14 22:29:44 +03:00
parent 732f30858b
commit 1e31c46256
6 changed files with 28 additions and 6 deletions

View File

@ -65,7 +65,11 @@
{% csrf_token %}
<input type='submit' value='Lubię to' class="btn btn-list" /></p>
</form>
{% if user.is_authenticated %}
<a class="btn btn-list" href="{% url 'koszyk_add' events.id %}">Dodaj do koszyka</a>
{% else %}
<a class="btn btn-list" href="{% url 'account_login' %}">Dodaj do koszyka</a>
{% endif %}
{% endif %}

View File

@ -50,11 +50,16 @@
<div class="grid article3">
<div class="showcase-text">
<h1>Zaplanowane Wydarzenia:</h1>
{% for i in latest_news_list %}
<p>Nazwa: {{ i.title }}</p><b></b>
<p>Data: {{ i.data }}</p><b></b>
<p>Miasto: {{ i.place }}</p><b></b>
<p>Opublikowane: {{ i.pub_date }}</p><br>
{% for i in zaplanowane %}
<h2>Nazwa: {{ i.event.title }}</h2><b></b>
<h3>Data: {{ i.event.data }}</h3><b></b>
<p>Miasto: {{ i.event.place }}</p><b></b>
<p>Opublikowane: {{ i.event.pub_date }}</p><br>
<a class="btn btn-list" href="{% url 'events:detail' i.event.id %}">Szczegóły</a>
<form method='POST' action="{% url 'delete' i.id %}">
{% csrf_token %}
<input class="btn btn-list" type='submit' value='Usuń' />
</form>
{% endfor %}
</div>
</div>

View File

@ -238,6 +238,7 @@ def koszyk(request):
paginator = Paginator(latest_news_list, 10)
numofnews = len(Event.objects.all())
categories = Category.objects.all()
zaplanowane = Koszyk.objects.all()
try:
users = paginator.page(page)
except PageNotAnInteger:
@ -254,6 +255,7 @@ def koszyk(request):
'users': users,
'category': Category.name,
'categories': categories,
'zaplanowane': zaplanowane,
}
return render(request, 'events/koszyk.html', context)
@ -264,6 +266,16 @@ def koszyk_add(request, pk):
koszyk = Koszyk.objects.filter(user=request.user, event=event).first()
if not koszyk:
koszyk = Koszyk(user=request.user, event=event)
#koszyk.user = request.user
#koszyk.event = event
koszyk.quantity += 1
koszyk.save()
return HttpResponseRedirect(reverse('koszyk'))
return HttpResponseRedirect(reverse('koszyk'))
def delete_koszyk(request, pk):
obj = get_object_or_404(Koszyk, id=pk)
if request.method == "POST":
obj.delete()
return HttpResponseRedirect("../../koszyk/")

View File

@ -28,6 +28,7 @@ urlpatterns = [
path('profil/', views.index2, name='profil'),
path('koszyk/', views.koszyk, name='koszyk'),
path('add_koszyk/<int:pk>/', views.koszyk_add, name='koszyk_add'),
path('<int:pk>/delete/', views.delete_koszyk, name='delete'),
path('profil/add_event/', views.create),
path('profil/add_category/', views.createCategory),
path('all_events/category/<int:pk>/', views.listofcategories, name='listofcategories'),