Answer the question
In order to leave comments, you need to log in
How to create multilevel URLs based on model properties?
All the best, I would like to ask how to make multi-level URLs according to the model.
For example, there is an Article model (articles), it has a ForeignKey binding to a Category, both models have a url. There is also a game property, there is also a binding to the model, but through manytomany Game, it also has a url.
I made an absolute reference to the Article model in the model like this:
def get_absolute_url(self):
games = self.games.all()[0]
return reverse('article_detail_link', kwargs={'category': self.category.url, 'games': games.url, 'slug': self.url})
path('articles/game/<category>/<slug>/', views.ArticleDetail.as_view(), name="article_detail_link"),
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question