0๐
โ
You can add a method get_user_public_profile_url
in your Product model, which returns the profile URL of the product.user
from django.urls import reverse
class Product(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=50)
...
def get_user_public_profile_url(self):
return reverse('Public-Profile', kwargs={'slug': self.user.profile.slug})
and in your template, change this line
<a href="{% url 'Public-Profile' %}">
to
<a href="{{ product.get_user_public_profile_url }}">
๐คSumithran
1๐
Try adding a slug
parameter to your url, that leads to the product related user profile slug product.user.profile.slug
{% for product in products %}
<div class="col-md-3">
<div class="card my-2 shadow-sm bg-body">
<div class="card-head">
<a href="{% url 'Public-Profile' slug=product.user.profile.slug %}">
<span class="material-symbols-outlined">
account_circle
</span>
{{ product.user.username }}
</a>
</div>
</div>
</div>
{% endfor %}
๐คweAreStarsDust
- [Answered ]-Django registration redux registration only with email (no password)
- [Answered ]-Return a model from a custom query without hitting the database
- [Answered ]-NoReverseMatch error in django app
- [Answered ]-Django Model Design Help with Many2Many
- [Answered ]-Django HTML5 Boilerplate header and footer
Source:stackexchange.com