Re: Raw SQL - How to approach paging and lazy fetching

2017-06-21 Thread Kevin Yu
Thanks Jani. I was able to solve my original issue using your suggestion. On Friday, June 16, 2017 at 12:54:26 PM UTC-7, Jani Tiainen wrote: > > Yes, even there isn't real foreign keys in the database you can still > join models. > > Have been doing that few times with legacy database. When defi

Re: Raw SQL - How to approach paging and lazy fetching

2017-06-16 Thread Jani Tiainen
Yes, even there isn't real foreign keys in the database you can still join models. Have been doing that few times with legacy database. When defining fkey you need to point it to corresponding field in fkey attributes in your model if it isnt your target model pk. And you can join nonmanged mode

Re: Raw SQL - How to approach paging and lazy fetching

2017-06-16 Thread Kevin Yu
Hi Jani, Thanks for the link. I was aware of this link and actually followed the steps when I started the project. I tried using model but then found out when i need to query a join, it doesn't seem to work unless there's a foreign key between the two models, however, given it's a legacy databa

Re: Raw SQL - How to approach paging and lazy fetching

2017-06-15 Thread Jani Tiainen
Hi, Even you do have legacy database, you can use unmanaged models and then leverage full power of ORM [1]. Just create models and in their Meta set managed = False and there you go. And what comes to paging - you need to somehow pass offset and limit to your query. [1] https://docs.djang

Raw SQL - How to approach paging and lazy fetching

2017-06-15 Thread Kevin Yu
Hi All, I am using raw sql to connect to database. The reason we used raw sql instead of the Django model is because the database is legacy and is being shared by multiple applications... I have one use case that I'm struggling right now. Basically I have a page that fetch more than 1000 resul