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.djangoproject.com/en/1.11/howto/legacy-databases/
On 16.06.2017 02:05, Kevin Yu wrote:
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 results. My query is like this:
|
cursor = connection.cursor()
cursor.execute('''
SELECT br.id, br.name, br.created_at, br.updated_at,
br.branchpoint_str, br.source
FROM branches as br
LEFT JOIN branches_projects as bp
ON br.id = bp.branch_id
WHERE bp.project_id = "%s" AND source != "other"
ORDER BY updated_at DESC
''', [int(project_id)]
)
|
Then in my template, I have this:
|
{% for br in special_branches %}
<tr class="{% if forloop.counter|divisibleby:2 %}even{% else
%}odd{% endif %} highlightable"
link="/files/{{build.image_path}}/build{{build.build_number}}/">
<td class="selectable">{{br.name}}</td>
<td class="selectable">{{br.branchpoint}}</td>
<td class="selectable center">{{ br.source|upper }}</td>
<td class="selectable center">{{br.updated_at}}
<td class="selectable center">{{br.built_at}}</td>
</tr>
{% endfor %}
|
The current problem is this would create a very long page... I am
wondering how to approach this problem so that I can have different
page on the template, and say 100 result per page, when i click the
second page, then django will fetch result 100-200.
Thanks!
--
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
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f6a3df97-8218-4fb8-b200-f4535797e135%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/f6a3df97-8218-4fb8-b200-f4535797e135%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
Jani Tiainen
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/025f11bd-a9c4-f7da-8b1d-44429237299a%40gmail.com.
For more options, visit https://groups.google.com/d/optout.