Hi, sometimes I find myself in a need of raw sql, for example when joining tables that don't have explicit related fields. In those cases "extra" method comes in really handy. For example I have following models.
class TagName(models.Model): name = model.CharField() class Tag(models.Model): content_type = model.ForeignKey(ContentType) object_id = model.IntegerField() tags = model.ManyToManyField(TagName) class WhateverObject(models.Model) ... owner_id = model.ForeignKey(User) ... And I want to get all "TagName"s of objects in a model owned by particular user. Getting only names is easily done extending 'tables' and 'where' part of the "extra" method, but when it comes to counting the number of objects tagged by one tag, I miss the "group by" part of the select statement. One of the solutions would be to return all TagNames and then count them within the python, and the other would be to fall completely to sql in Manager of "TagName". Somehow it seems that using only SQL would be quicker, but at the same time less readable and not database independent. What do django-developers usually prefer? Mladen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---