Tuesday, August 30, 2011

Re: Combining queries? A "join" in Python?

On Aug 30, 3:10 am, graeme <graeme.piete...@gmail.com> wrote:
> I think I need to restate this question with the actual models.

Apologies in advance for answering a question you didn't ask, but is
your subcategory model truly representing something different from
your category model? I think the problems you are having with the
query may be indicative of a problem with your model definitions /
database layout.

Unless I have the wrong idea about what you are trying to accomplish,
I recommend a single Category model with a parent field defined as a
back-reference to itself. Something like this:

parent = models.ForeignKey('self', blank=True, null=True,
related_name='child')

This approach would eliminate the SubCategory and SubCategoryText
models. The CategoryText looks about right as it is.

I'm not clear on precisely what you are trying to accomplish with your
query, but perhaps rethinking your models will make the query easier.


Hope that helps,

--Stuart

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment