product detail

This commit is contained in:
Sharad Ahlawat 2020-03-10 14:10:36 -07:00
parent 961b4b200b
commit b46e94fda0
5 changed files with 57 additions and 2 deletions

7
producthunt/static/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,8 @@
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- Bootstrap core CSS. Adding local file enable pycharm to auto-complete CSS tags -->
<link href="{% static 'bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'open-iconic/font/css/open-iconic-bootstrap.css' %}" rel="stylesheet">
<!-- Favicons -->

View File

@ -0,0 +1,40 @@
{% extends 'base.html' %}
{% block content %}
{% if error %}
{{ error }}
<br/>
<br/>
{% endif %}
<div class="row">
<div class="col-2">
<img src="{{ product.icon.url }}" class="img-fluid" \>
</div>
<div class="col-10">
<a href="{{ product.url }}"><h1>{{ product.title }}</h1></a>
</div>
</div>
<hr />
<div class="row">
<div class="col-8">
<img src="{{ product.image.url }}" class="img-fluid" \>
</div>
<div class="col-4">
<a href=""><button class="btn btn-primary btn-lg btn-block"><span class="oi oi-caret-top"></span> Up Vote : {{ product.votes_total }}</button></a>
</div>
</div>
<hr />
<div class="row">
<div class="col-4">
<h4>Hunted by: {{ product.hunter.username }}</h4>
</div>
<div class="col-4 text-right">
<h4>{{ product.pubdate_pretty }}</h4>
</div>
</div>
<hr />
<div class="row">
<div class="col-8">
<p>{{ product.body }}</p>
</div>
</div>
{% endblock %}

View File

@ -3,4 +3,5 @@ from . import views
urlpatterns = [
path('create', views.create, name='create'),
path('<int:product_id>/', views.detail, name='detail'),
]

View File

@ -1,4 +1,4 @@
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from .models import Product
from django.utils import timezone
@ -25,8 +25,13 @@ def create(request):
product.pubdate = timezone.datetime.now()
product.hunter = request.user
product.save()
return redirect('home')
return redirect('/products/' + str(product.id))
else:
return render(request, 'products/create.html', {'error': 'all fields required'})
else:
return render(request, 'products/create.html')
def detail(request, product_id):
product = get_object_or_404(Product, pk=product_id)
return render(request, 'products/detail.html', {'product': product})