Here is my code:

#in models.py
class Instructor(models.Model):
    prefix = models.CharField(max_length=50, blank=True, null=True)
    first_name = models.CharField(max_length=50)
    middle_name = models.CharField(max_length=50, blank=True,
null=True)
    last_name = models.CharField(max_length=50)
    suffix = models.CharField(max_length=30, blank=True, null=True)

    def __unicode__(self):
        return self.last_name + ' ' + self.first_name


class Student(models.Model):
    instructors = models.ManyToManyField(Instructor)
    first_name = models.CharField(max_length=50)
    middle_name = models.CharField(max_length=50, blank=True,
null=True)
    last_name = models.CharField(max_length=50)
    suffix = models.CharField(max_length=30, blank=True, null=True)

    def __unicode__(self):
        return self.last_name + ' ' + self.first_name


#in views.py

def show_student(request, id)
    student = Student.objects.get(id=id)
    instructors = student.instructors.all()
    return render_to_response('student.html', locals())


#in student.html
...
<ul>
{% for instructor in instructors %}
    <li>{{ instructor.first_name }}</li> #there is no value output
here
{% endif %}
</ul>

Thoughts?

On May 18, 5:56 pm, Brandon Taylor <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> I have a ManyToMany field on a model, and when I want to get the
> related items and display them in a template in a for loop, the loop
> executes the correct number of times, but in my output blocks there
> are no values.
>
> If I print the object, I get an array of values, same as any other
> object, but I can't output anything.
>
> Thoughts? I'm starting to get stumped.
>
> Brandon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to