Render A List Of Foreign Key In Template
Models class Head_of_department(models.Model): first_name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) email = models.CharField(max_l
Solution 1:
I found the solution , I wrote views incorrectly.
model = Attendance
fields = ['employee']
success_url = '/dashboard/'
def get_context_data(self,** kwargs):
context = super(Attendancecreate, self).get_context_data(**kwargs)
email = self.request.user.email
hod = Head_of_department.objects.get(email=email)
context["objects"] = Employee.objects.filter(head_of_department =hod)
print (context["objects"])
return context
Template
{% for emp in objects %}
{{ emp.first_name }} {{ emp.last_name }}
{% endfor %}
Post a Comment for "Render A List Of Foreign Key In Template"