4
Why did you put the get_absolute_url
method on a proxy, rather than the User model itself? If you wanted to do this, you would have to use UserMethods as the model in your view.
But the fix for the other approach is to get the user_id from self.object
:
return reverse('companies:user_detail', kwargs={'user_id': self.object.id})
2
Try this on your model.
class UserMethods(User):
def get_absolute_url(self):
return reverse('companies:user_detail', args=(self.id,))
Whenever you want to provide this url in the template just type {{ object.get_absolute_url }}
.
- [Django]-Django settings based on IP or hostname
- [Django]-How make conditional expression on Django with default value of object?
- [Django]-Link with parameter in Django templates
- [Django]-Django-rest ModelSerializer select fields to display in nested relationship
Source:stackexchange.com