I use this technique often. I have a few scenarios where I need to convert data before presenting them to the user, and I use that.
I have used that to even join tables that live on separate databases (via Postgres FDW) and present them to the user in a map or a table-view. If this takes a lot of heat, it can be a problem. You can maintain materialized views however. If you don't like mat-views, you can create an actual table that when one of them objects change, you use the save signal, to update that table as well. Or do it as a trigger in the database. On Mon, Feb 9, 2015 at 4:06 AM, Eric Man <meric...@gmail.com> wrote: > Hello everyone, > > We've got a few models whose relationships are quite "involved" and I > couldn't figure out how to simplify it further. > > We need to query them using a GROUP BY query, which Django's ORM only > provides limited support. > > So I've built a postgres view and a managed=False model in Django so we > can continue to use the ORM to further specify the query when needed. > > i.e. https://gist.github.com/meric/d3a92402982c0dd3bb23 > > What do you think of this technique? Is it a good practice, have you tried > it before, or do you foresee I'll experience performance challenges later > on? > > I'm worried about this because this view-model is going to be heavily > relied upon and its query in CPU time would be more than any others. > > I know this because we're refactoring our website and I hope I can remove > all the series of ORM queries in our code that are merged together and > paginated by python (rather than in the database itself as is typical > practice), which is slow and the code hard to read, with this one model > based on postgres view. > > Best Regards, > Eric > > -- > 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+unsubscr...@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/3e4f9e4f-3a7a-447a-bf29-7547d049ae04%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/3e4f9e4f-3a7a-447a-bf29-7547d049ae04%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- George R. C. Silva SIGMA Consultoria ---------------------------- http://www.consultoriasigma.com.br/ -- 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+unsubscr...@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/CAGyPVTsA_o5i0PK2_Cw5pOymFg0FGxSH7UWv3EADRA%3DTtFwM_Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.