Sunday, November 3, 2013

Django - How to combine queries in to one and display it in the template?

Suppose this is a model for an app Blog:

  class Blog(models.Model):      title = models.CharField(max_length=200)      pub_date = models.DateTimeField(default=datetime.now)      creator = models.ForeignKey(User)      content = BleachField()

And this is another model for an app Status:

  class Status(models.Model):      content = BleachField()      pub_date = models.DateTimeField(default=datetime.now)      creator = models.ForeignKey(User)

How do I come up with something like this:

  from blog.models import Blog  from status.models import Status    blog = Blog.objecs.all()  status = Status.objects.all()  all = blog | status

And display all the updates for the user in the template.

  updates = user.all_set.all()

So that in the templates I can do, something like this:

  {% for each in all %}      ....  {% endfor %}

What I wan't is that, in the home page, I would like to display the updates of all the user's activity in the latest order,

Eg:

  'User updated with new status: blah blah'  'User published a new Blog'  'User published a new Blog'

like in many other social networking sites. And not to display them both separately. And similarly in the user's profile, display all the activities of that particular User.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B4-nGoMQWG0dhwVTbyJnW6O%2BZaJr4Qvrci1aMGYpZrtbTUukw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment