in my humble opinion, don't care about messiness in the template, since
messiness in the code is way worse.
nontheless, you should be able to render the two querysets in the same
template without additional hassle! Templates know nothing about models. The
deal with lists when it comes to querysets. ( {% for i in queryset %} will
do whatever results com in there. ) Maybe you have to write code to render
one field or another depending on its presence, which you can check with {%
if field %} {{ field }} {% else %} {{anotherfield }} {% endif %}
Finally, as such, I don't see how to return a related model row asking for a
given model objects.
haroldo
2009/9/17 Milan Andric <[email protected]>
>
> Hello, I'm not sure if the subject makes sense but i have two models:
>
> class Profile(models.Model):
> user = models.OneToOneField(User, primary_key=True)
> middle_name = models.CharField(max_length=50, blank=True)
> title = models.CharField(blank=True, max_length=128)
> about = models.TextField(blank=True,help_text="A few sentences
> about yourself - capsule biography. No HTML allowed.")
> ...
>
> class Alumni(models.Model):
> profile = models.OneToOneField(Profile, primary_key=True)
> grad_year = models.IntegerField('Graduation
> year',max_length=4,choices=constants.YEARS, null=True)
> third_year = models.BooleanField('Is this student on the 3-year
> plan?',default=False)
> ...
>
> Now I'm working on a search page for people and it's easy enough to do
> a query on each model to get results. But each queryset would be on a
> different model so the template would have to deal with a queryset on
> Profile, Alumni, or any other extended class that I have. That seems
> kind of messy in the template.
>
> So is there a way I can query on Alumni.objects.filter(**query_params)
> but then return the Profile objects related to the Alumni objects
> rather than the Alumni objects? This would allow me to always treat
> the results the same in the template regardless of what Profile
> extension I am querying.
>
> Thanks for you help,
>
> Milan
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---