Answer the question
In order to leave comments, you need to log in
Django request in model - how to change link?
There is the following model code:
def get_absolute_url(self):
return reverse('vehicle-detail', kwargs={'pk': self.pk})
Answer the question
In order to leave comments, you need to log in
I myself have not been working with Django for long, but there is an opinion that the model should not know anything about requests. Therefore, I would form the URL not in the model, but, for example, in views.py
Please describe in more detail why you need it.
Probably in case the user has the `is_stuff` flag set, he gets more information about the object. Maybe the pattern is different. And for this, separate pages with different URLs are made for admins and non-admins. But why? I would make it simpler: let the URL be the same for everyone, and only the final page, or rather, its view, independently determines, based on `request.user`, what to do, what to show to the user, with what template.
Otherwise, the admins will want to share the link to the page somewhere, an outsider will poke - and there 403.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question