Skip to content

Commit

Permalink
created slugs and attached detail view links
Browse files Browse the repository at this point in the history
  • Loading branch information
vykuntaharsha committed Nov 19, 2017
1 parent 62ef522 commit 0e2e1e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/myWebsite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
url(r'^admin/', admin.site.urls),
url(r'^$', TemplateView.as_view(template_name='home.html')),
url(r'^restaurants/$', RestaurantListView.as_view()),
url(r'^restaurants/(?P<rest_id>\w+)/$', RestaurantDetailView.as_view()),
url(r'^restaurants/(?P<slug>[\w-]+)/$', RestaurantDetailView.as_view()),
# url(r'^restaurants/chicken/$', ChickenRestaurantListView.as_view()),
url(r'^about/$', TemplateView.as_view(template_name='about.html')),
url(r'^contact/$', TemplateView.as_view(template_name='contact.html')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h1>Restaurant List</h1>

<ul>
{% for obj in object_list %}
<li>{{obj.name}} <br>
<li><a href="/restaurants/{{ obj.slug }}/"> {{obj.name}} </a><br/>
{{obj.name}} | {{obj.name}} | {{obj.location}} |
{{obj.category}} | {{obj.timestamp}} | {{obj.updated}}
</li>
Expand Down
9 changes: 5 additions & 4 deletions src/restaurants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def get_queryset(self):
class RestaurantDetailView(DetailView):
queryset = RestaurantLocation.objects.all()

def get_object(self, *args, **kwargs):
rest_id = self.kwargs.get('rest_id')
obj = get_object_or_404(RestaurantLocation, id= rest_id)
return obj
# def get_object(self, *args, **kwargs):
# rest_id = self.kwargs.get('rest_id')
# obj = get_object_or_404(RestaurantLocation, id= rest_id)
# return obj

0 comments on commit 0e2e1e8

Please sign in to comment.