views:

248

answers:

2

Would like to hear your opinion. At the current stage (1.1) would you use generic relations in django or stick to more traditional modeling - given that it's yet impossible to traverse and filter against such relations easily (compared to ForeignKey, ManyToMany, OneToOne relations)?

Here is one example - I keep track in the database when each page was last seen by each user, when he/she decided to "follow" an article, how often do they want to receive email updates and when they requested one last time, when such email was last sent to the user and the log of page revisions.

So to build a meaningful email digest I have to construct pretty heavy queries so that users don't get more email than they ask for and the messages be most informative and brief.

One way to do it - define Activity model that can fit possibly any scenario and connect them to other models with using generic relation, another way - define separate models PageView, EmailUpdateLog, EmailSubscription and access them the "usual way".

The downside of using generic relation - it's harder to code complex queries and they will run slower, upside - less code in models and easier access to generalized objects (e.g. Activity).

Have you found a scenario where generic relation give you a huge advantage, beside just being an interesting concept?

Maybe you found some other way to emulate generic relations?

Thanks.

A: 

All depends on your requirements/tasks..

For some tasks generic relations are fine (and I use them) For other better use "traditional modeling"

Pydev UA
"For some cases it is good; for some it is not good." Thank You for saying nothing.
Lakshman Prasad
+2  A: 

I would question your starting assumption:

given that it's yet impossible to traverse and filter against such relations easily

I don't think it's particularly difficult to traverse and filter generic relations. As long as you define both ends of the relationship, both forwards and backwards traversals work much the same as they do with normal ForeignKeys.

It's perfectly possible to make these queries as efficient as normal relationships, so I don't really see much of a problem.

Daniel Roseman
don't you need extra two joins per generic relation? so they can't be as efficient - at the database level at least.
Evgeny
Perhaps you should implement it and profile your code before making that assumption.
Soviut