Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 June 22, 2010 03:39:29

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

One to many django pagination


Hi,

i recently encountered a problem due to inefficient performance of
django pagination. After researching, i realized that there is a need
to use django database queries when dealing with django-pagination as
"LIMIT" will automatically be added. This is useful especially when
dealing with huge chunk of data.

However, i came across a problem where i could not figure out how to
use django database query to extract the data.

Lets say i have 3 tables, "Teachers", "Students", and
"Teachers_profile" with a one-many relationship.

The Teacher table contains teacher_id,.....(teacher info)
The Student table contains student_id,name,...(student info)
The Teacher_profile table is the link between the 2 tables. It
contains teacher_id,student_id

How can i use django database query with filters to extract the
teachers who is managing a student named "Jonny" for example?

i'm not sure if this is an easy question, but i'm having some trouble
in solving it :(

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 22, 2010 09:10:35

e.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

One to many django pagination


If i understand you correctly you've got a couple of solutions. You
can define a "through" relationship between Student and Teacher usinf
Techer_profile as the "through" table (http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships).
Then you should be able to do:

teachers = Teacher.objects.filter(student__name="Jonny")

I think the ORM should take care of this query for you and select only
those teachers.

Euan

On Jun 22, 3:39 am, Jx <l3earl3ea...@gmail.com> wrote:
> Hi,
>
> i recently encountered a problem due to inefficient performance of
> django pagination. After researching, i realized that there is a need
> to use django database queries when dealing with django-pagination as
> "LIMIT" will automatically be added. This is useful especially when
> dealing with huge chunk of data.
>
> However, i came across a problem where i could not figure out how to
> use django database query to extract the data.
>
> Lets say i have 3 tables, "Teachers", "Students", and
> "Teachers_profile" with a one-many relationship.
>
> The Teacher table contains teacher_id,.....(teacher info)
> The Student table contains student_id,name,...(student info)
> The Teacher_profile table is the link between the 2 tables. It
> contains teacher_id,student_id
>
> How can i use django database query with filters to extract the
> teachers who is managing a student named "Jonny" for example?
>
> i'm not sure if this is an easy question, but i'm having some trouble
> in solving it :(

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 22, 2010 09:39:23

jx j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

One to many django pagination


Oh, i guess i didn't define my models using the "through" relationship.
Thanks for the help! :)

On Tue, Jun 22, 2010 at 4:10 PM, euan.godd...@googlemail.com <
euan.godd...@gmail.com> wrote:

> If i understand you correctly you've got a couple of solutions. You
> can define a "through" relationship between Student and Teacher usinf
> Techer_profile as the "through" table (http://docs.djangoproject.com/> en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships<http://docs.djangoproject.com/%0Aen/dev/topics/db/models/#extra-fields-on-many-to-many-relationships>
> ).
> Then you should be able to do:
>
> teachers = Teacher.objects.filter(student__name="Jonny")
>
> I think the ORM should take care of this query for you and select only
> those teachers.
>
> Euan
>
> On Jun 22, 3:39 am, Jx <l3earl3ea...@gmail.com> wrote:
> > Hi,
> >
> > i recently encountered a problem due to inefficient performance of
> > django pagination. After researching, i realized that there is a need
> > to use django database queries when dealing with django-pagination as
> > "LIMIT" will automatically be added. This is useful especially when
> > dealing with huge chunk of data.
> >
> > However, i came across a problem where i could not figure out how to
> > use django database query to extract the data.
> >
> > Lets say i have 3 tables, "Teachers", "Students", and
> > "Teachers_profile" with a one-many relationship.
> >
> > The Teacher table contains teacher_id,.....(teacher info)
> > The Student table contains student_id,name,...(student info)
> > The Teacher_profile table is the link between the 2 tables. It
> > contains teacher_id,student_id
> >
> > How can i use django database query with filters to extract the
> > teachers who is managing a student named "Jonny" for example?
> >
> > i'm not sure if this is an easy question, but i'm having some trouble
> > in solving it :(
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 15th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support