1👍
✅
The problem is that your’re trying to use attributes from Project
when accessing a uProjects
in the template, since on your view you’re retrieving a list of uProjects
when issuing uProjects.objects.filter(user=user)
.
myprojects.html
{% extends "main/base.html" %}
{%block title %}My Projects{% endblock %}
{% block content %}
<ul>
{% for uproj in object_list %}
<li>
Project: {{uproj.project.name}}, of {{uproj.project.department}} Department. <a href="/project/{{uproj.project.name}}/">View Details.</a>
</li>
{% endfor %}
</ul>
{% endblock %}
You should also set the user as request.user
on your view.
views.py:
@login_required
def myProjects(request):
user = request.user
object_list=uProjects.objects.filter(user=user)
context = {
'object_list': object_list,
}
return render(request, 'projects/myprojects.html', context)
Source:stackexchange.com