That did the trick! Thanks!
On 3/26/07 5:11 PM, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > You are so close! this is a very common question. > > you want something like: > {% for school_emp in School.schoolpersonel_set.all %} > > But passing in the Model class 'School' is considered bad form. > > In your view, add the result of all() to your context: > extra_context['personel'] = School.schoolpersonell_set.all() > render_to_response(...., context=extra_context) > > Then in the template: > {% for person in personel %} > > I am leaving out some details on the view code, so here is a full > implementation: > > # assuming NCESSID is required and unique. > def school_personel(request, ncessid): > school = get_object_or_404(School, NCESSID=ncessid) > extra_context = { 'school': school, > 'personel': school.personel_set.all() } > > return render_to_response('school_personel.html', extra_context, > > context_instance=RequestContext(request)) > > Now for some advanced stuff: > > def all_personel(request): > personel = personel.objects.order_by('school') > extra_context = {'personel': personel} > return render_to_response('all_personel.html', extra_context, > > context_instance=RequestContext(request)) > > all_personel.html: > > {% regroup personel by school as personel_by_school %} > {% for school_personel in personel_by_school %} > {{ school_personel.grouper.name }} <!-- school_personel.grouper is > a School object --> > {% for person in school_personel.list %} > {{person.first_name}} {{person.last_name}} > {% endfor %} > {% endfor %} > > > Hope that helps!!! > > On Mar 26, 5:44 pm, "Paul G. Barnes" <[EMAIL PROTECTED]> wrote: >> OK, I'm a Python/Django newbie (more or less), and I have a problem. >> >> I had these two models (details stripped for clarity: >> >> class School(models.Model): >> ... >> name = models.CharField() >> street = models.CharField() >> mail = models.CharField() >> city = models.CharField() >> state = models.USStateField() >> zip = models.CharField() >> plus_four = models.CharField() >> phone = models.PhoneNumberField() >> fax = models.PhoneNumberField() >> NCESSID = models.CharField() >> ... >> def __str__(self): >> return self.name >> >> class SchoolPersonnel(models.Model): >> ... >> school = models.ForeignKey('School') >> honorific = models.CharField() >> title = models.CharField() >> first_name = models.CharField() >> last_name = models.CharField() >> email = models.EmailField() >> phone = models.PhoneField >> ... >> def __str__(self): >> return '%s, %s' % (self.last_name, self.first_name) >> >> I want a page that will list the school details and include all the >> personnel associated with that school. Like this: >> >> Some High School >> Address >> City, Sate zip >> >> Phone >> Fax >> >> Personnel >> Mr. Smith Principal [EMAIL PROTECTED] >> Mrs. Williams Counselor [EMAIL PROTECTED] >> Etc. >> >> I've tried using School.schoolpersonnel_set.all() but you can't access the >> details (i.e. School.schoolpersonnel_set.objects.title) because the >> "'RelatedManager' object has no attribute 'objects'". >> >> I've tried to iterate through School.schoolpersonnel_set.all(), on the >> template, but I can't figure out what the instances of >> School.schoolpersonnel_set.all() are called. >> >> {% for SchoolPersonnel in School.schoolpersonnel_set %} gives me an >> "iteration over non-sequence" error. >> >> I've tried a bunch of other things that don't work either. >> >> I know that there is something in School.schoolpersonnel_set but I don't >> know how to get it onto the web page. >> >> I've been working on this for about a week now. I've looked through the >> documentation, the django book, and the archives of this list. I've even >> tried looking at code from other applications, but I can't seem to find >> anything on point. >> >> Can anyone help me? >> >> -- >> Pgb > > > > -- Pgb --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---