On Sun, 3 Nov 2013 18:31:42 +0530 Robin Lery <robinl...@gmail.com>
wrote:
> Suppose this is a model for an app Blog:
> class Blog(models.Model):
<snip>
> And this is another model for an app Status:
> class Status(models.Model):
<snip>
> How do I come up with something like this:
<snip>
> 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.

There are two (actually three) ways to get something like that:
 1. Derive Blog and Status from the same concrete basemodel. Then you
    can get all the basemodel-instances ordered by time. Of course the
    publishing-time (and author and such things) would have to be fields
    on the basemodel or present on all derived classes.
    Advantage: You get the ordering and limiting done in the database.
    Disadvantage: A lot of joins in the database.
 2. You do the ordering in the python-code in the view.
    Advantage: No concrete inheritance and thus no joins.
    Disadvantage: No sorting and limiting in the db (which is faster
    with that than your python-code will be).
 3. ( Use a schema-free database, called NO-SQL in newer times, and
    connect the entries freely. )

Whether to choose 1. or 2. depends on what you do more: Do you fetch
mixed lists and want them ordered? Or do you mainly fetch lists of
specific types and only want the ordering in one or two places? Will
the joins in database-space or the ordering in python-space hurt you
more.

Have fun,

Arnold

Attachment: signature.asc
Description: PGP signature

Reply via email to