class host(models.Model): emp = models.ForeignKey(getname) def __unicode__(self): return self.topic
In views there is the code as,
real = for emp in my_emp: real.append(host.objects.filter(emp=emp.id))
This above results only the values of emp,My question is that how to get the ids along with emp values.
Just add them to the list when you are processing
my_emp list, something like that:
real =  for emp in my_emp: real.append((emp.id, host.objects.filter(emp=emp.id)))
for emp_id, host in real: # do something usefull
You can also get list of all emp objects for given host object by:
emp_list = host.emp_set.all()
You probably want to do this whole thing in a single query:
which will get you queryset of all Host objects for your list of emp ids.