2👍
✅
You shouldn’t alter the slug in the db. Separate the slug
and id
in the url:
url(r'^(?P<slug>[\w\-]+)-(?P<pk>\d+)/$', 'submit_deals.views.deal_page',
name='deal_page'),
An then use pk
to get the object and ignore the slug
:
def deal_page(request, slug, pk):
try:
deal = SubmitDeal.objects.get(pk=pk)
context_dict = {'deal_title': deal.deal_title, 'deal': deal}
except SubmitDeal.DoesNotExist:
context_dict = {}
return render(request, 'deal_page.html', context_dict)
Source:stackexchange.com