On Fri, Apr 10, 2009 at 4:40 PM, veearrsix <stup...@googlemail.com> wrote:

>
> This question seems to have been asked a few times, but never answered
> fully.
>
> I am looking to query more than one table, but return the results to a
> template as one queryset ordered by date.
>
> The reason i'm doing this is to create a single queryset including
> information from a blog table, twitter table and delicious table to be
> displayed as a sort of log of my online activity sorted by date.
>
> the blog post model:
>
> class Post(models.Model):
>    slug = models.SlugField(unique=True)
>    tags = TagField()
>    title = models.CharField(max_length=80)
>    pubdate = models.DateTimeField(default=datetime.datetime.now)
>    modifieddate = models.DateTimeField(auto_now=True)
>    body = models.TextField()
>    draft = models.BooleanField(default=True)
>    closed = models.BooleanField()
>
> the delicious model (taken from syncr app)
>
> class Bookmark(models.Model):
>    # description, href, tags, extended, dt
>    description = models.CharField(max_length=250, blank=True)
>    url = models.URLField(unique=True)
>    tags = TagField()
>    extended_info = models.TextField(blank=True)
>    post_hash = models.CharField(max_length=100)
>    saved_date = models.DateTimeField()
>
> the twitter model (taken from syncr app)
>
> class Tweet(models.Model):
>    pub_time    = models.DateTimeField()
>    twitter_id  = models.PositiveIntegerField()
>    text        = models.TextField()
>    user        = models.ForeignKey('TwitterUser')
>
>
> I'd like to get these into one queryset, possibly including a field
> that indicates what type of listing is being displayed. Obviously I
> dont need all of the fields from each of the models, just enough to
> display the title and a possible link.
>
> Thanks in adance, hope someone can help me out, I don't know where to
> start with this.
> >
>
There is no way to get a single QuerySet with results from multiple models.
What you want to do is best approximated like this:

from itertools import chain

sorted(chain(Model1.obejcts.all(), Model2.objects.all()), key=lambda o:
o.pub_date)


Alex
-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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

Reply via email to