Hi Vijay,

Thanks very much for your assistance and recommendation. i will get back to
you if needed more help.

Sum

On Fri, Jan 9, 2015 at 3:15 PM, Vijay Khemlani <[email protected]> wrote:

> Well, you can do something like this
>
> one_leave = leave.objects.get(pk=1) # Asuming there is a leave with pk 1
> print one_leave.staff.First_Name    # Automatically joins with the staff
> table to print the first name of the associated staff
>
> Or something like this
>
> one_staff = staff.objects.get(pk=1) # Asuming there is a staff with pk 1
> staff_leaves = one_staff.leave_set.all()
> for staff_leave in staff_leaves:
>     print staff leaves                    # Print all the leaves of a
> particular staff
>
> Also, I recommend you to follow Python and Django naming conventions, that
> is classes in CamelCase ("Staff" and "Leave" instead of "staff" and
> "leave") and fields in underscore (first_name instead of First_Name, etc)
>
> On Thu, Jan 8, 2015 at 11:41 PM, sum abiut <[email protected]> wrote:
>
>> Hi,
>> i am trying to pull out all the information in both model. i can pull out
>> information in each table but i am a but confuse in joining the two tables
>> together. something like NATURAL JOIN in mysql.
>>
>> Cheers,
>>
>>
>> On Fri, Jan 9, 2015 at 12:07 PM, Vijay Khemlani <[email protected]>
>> wrote:
>>
>>> OK, what query are you trying to make? or what information do you want
>>> to display?
>>>
>>> On Thu, Jan 8, 2015 at 6:50 PM, sum abiut <[email protected]> wrote:
>>>
>>>> Hi Vijay,
>>>> Thank you for your email. Here is my models. i want to be able to pull
>>>> out all the data from both table and display them. i am a bit new to django
>>>> still finding my way out.
>>>>
>>>>
>>>> class staff(models.Model):
>>>>     First_Name = models.CharField(max_length=45)
>>>>     Last_Name =models.CharField(max_length=45)
>>>>     employee_Date=models.DateField()
>>>>     position=models.CharField(max_length =45)
>>>>     department=models.CharField(max_length =45)
>>>>     qualification=models.CharField(max_length =45)
>>>>     VNPF_no =models.CharField(max_length =45)
>>>>     salary =models.IntegerField()
>>>>     montly_salary=models.IntegerField()
>>>>     Training=models.TextField()
>>>>     username  =models.ForeignKey(User, default =1)
>>>>
>>>>     def __unicode__(self):
>>>>         return self.First_Name
>>>>
>>>> class leave(models.Model):
>>>>     leave_type =models.CharField(max_length=45)
>>>>     Specify_details=models.TextField(default="")
>>>>     start_Date =models.DateField()
>>>>     end_date=models.DateField()
>>>>     total_working_days=models.IntegerField()
>>>>     authorization =models.CharField(max_length=45)
>>>>     authorized_by=models.CharField(max_length=45,  default ="")
>>>>     remarks=models.TextField()
>>>>     authorizaion_date =models.DateField()
>>>>     username  =models.ForeignKey(User,  default =1)
>>>>     staff =models.ForeignKey(staff,  default =1)
>>>>
>>>>     def __unicode__(self):
>>>>         return self.leave_type
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Fri, Jan 9, 2015 at 8:32 AM, Vijay Khemlani <[email protected]>
>>>> wrote:
>>>>
>>>>> Please be more specific in your question, how are these tables
>>>>> related? what models are they associated with?
>>>>>
>>>>> On Thu, Jan 8, 2015 at 6:01 PM, sum abiut <[email protected]> wrote:
>>>>>
>>>>>> Hi,
>>>>>> can someone please help. i am trying to pull data from two table in
>>>>>> django and display the results. can someone please point me to the right
>>>>>> direction.
>>>>>>
>>>>>> kind regards,
>>>>>> Sum A
>>>>>>
>>>>>>
>>>>>>  --
>>>>>> 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 [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>> 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/CAPCf-y6DxaBuSiLYNr2dc3sAn70qB46_G5MTJzPoJPkG1-57PA%40mail.gmail.com
>>>>>> <https://groups.google.com/d/msgid/django-users/CAPCf-y6DxaBuSiLYNr2dc3sAn70qB46_G5MTJzPoJPkG1-57PA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>  --
>>>>> 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 [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> 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/CALn3ei0qKOsMrV-nVLrABSfBpbPAOCHgQDsaYXDS_EkNS4QEZw%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/django-users/CALn3ei0qKOsMrV-nVLrABSfBpbPAOCHgQDsaYXDS_EkNS4QEZw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>>>
>>>> -
>>>>
>>>> --
>>>> 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 [email protected].
>>>> To post to this group, send email to [email protected].
>>>> 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/CAPCf-y7%3D2xjk0xApyXpSnqvGHogYSdf7ztqnQUJtpvXSSamntQ%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAPCf-y7%3D2xjk0xApyXpSnqvGHogYSdf7ztqnQUJtpvXSSamntQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> 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/CALn3ei3OudzfSz6408Mt8wd7n6xXyyXdVyBdSVRLqzNuw9rCag%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CALn3ei3OudzfSz6408Mt8wd7n6xXyyXdVyBdSVRLqzNuw9rCag%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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/CAPCf-y5bSoxnbjtradesJha5FO6AJBw65ka3eKZz%3DQ9Qz1oupQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAPCf-y5bSoxnbjtradesJha5FO6AJBw65ka3eKZz%3DQ9Qz1oupQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/CALn3ei2_GOuY8YvoZhZfGC5Qs4LjF_FfU4VRrM0TqXf%3D2goB_Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALn3ei2_GOuY8YvoZhZfGC5Qs4LjF_FfU4VRrM0TqXf%3D2goB_Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAPCf-y4k%2BBX88WCWLYMN6BKasOOQb2p81zgo%3DxwMPgYVbQ0U2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to