Hi, You can already use any unique field as the slug field, for example:
path('product/<slug>/', views.ProductDetail.as_view()), ProductDetail(DetailView) model = Product slug_field = 'order_id' If you want to use a different name in the URL pattern, then set slug_url_kwarg [1]. path('product/<order_id>/', views.ProductDetail.as_view()), ProductDetail(DetailView) model = Product slug_field = 'order_id' slug_url_kwarg = 'order_id' Cheers, Alasdair On Wednesday, 2 January 2019 12:24:00 UTC, Osezele Orukpe wrote: > > Django class based generic views like DetailView, DeleteView and > UpdateView should be flexible enough to work with any unique field not just > slug and primary key field, > In real projects primary key and slugs are not used fetch data, a more > abstract unique key is preferred. > Yes, this can be easily done on our own but django can just ease that > extra stress by making these generic classes flexible enough to work with > any field of our choice in > the model given that the field is flagged as a unique field. > > so we could just use the DatailView as so: > > ProductDetail(DetailView): > model = Product > field = order_id > > instead of having to write a custom query(with the ORM) to fetch with > 'order_id' > > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ffa51fce-b9c8-4d52-bb10-fd75ff503bd0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.