Re: Models and relationships

2015-07-07 Thread Rafael E. Ferrero
Nice!! Chris good work !!

--
Rafael E. Ferrero

2015-07-06 20:15 GMT-03:00 Chris Strasser :

> WOO HOO !.. success ... thanks everyone...
>  just needed a nudge in the right direction  I will tackle the
> templates tomorrow and see where that takes me.
>
> On Mon, Jul 6, 2015 at 2:24 PM, Rafael E. Ferrero <
> rafael.ferr...@gmail.com> wrote:
>
>> contacts = Contacts.objects.select_related()
>>
>> --
>> Rafael E. Ferrero
>>
>> 2015-07-06 13:51 GMT-03:00 Florian Schweikert :
>>
>>> On 06/07/15 14:04, Chris Strasser wrote:
>>> > my problem is with reverse lookups (i think it is called) the docs say
>>> that i can access entries through blog.entry,(by lowercaseing the class)
>>> > it appears to me that i have the same setup with contact and location
>>> but i am getting errors ??
>>>
>>> I think you forgot about "_set".
>>> Try something like:
>>>
>>> Location.contact_set.all()
>>>
>>> And please don't use AutoField, db_column and primary_key until you have
>>> a good reason. Also ForeignKey fetches an object of the connected type,
>>> not an id, so "contactid", ... is confusing ;)
>>>
>>> --
>>> Florian
>>>
>>> --
>>> 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/559AB201.40600%40ist-total.org
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/YYM-cTEZOgA/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/CAJJc_8Vn72yWdFwUEFXRXD_4yOhD%2Bzx7n%3D0T189AsfGFU1n7Yg%40mail.gmail.com
>> 
>> .
>>
>> 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 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/CAH3cd3qiW0vKX_TxpmjuY5ZfVaVG2BPM1DK%2Byjt8Raw7-PrU0A%40mail.gmail.com
> 
> .
>
> 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 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/CAJJc_8V2V_22hz5s5k7ww7LEpfk6i%3D%2BjS6Vm%3DR%2Brnt5PpatQ4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models and relationships

2015-07-06 Thread Chris Strasser
WOO HOO !.. success ... thanks everyone...
 just needed a nudge in the right direction  I will tackle the
templates tomorrow and see where that takes me.

On Mon, Jul 6, 2015 at 2:24 PM, Rafael E. Ferrero 
wrote:

> contacts = Contacts.objects.select_related()
>
> --
> Rafael E. Ferrero
>
> 2015-07-06 13:51 GMT-03:00 Florian Schweikert :
>
>> On 06/07/15 14:04, Chris Strasser wrote:
>> > my problem is with reverse lookups (i think it is called) the docs say
>> that i can access entries through blog.entry,(by lowercaseing the class)
>> > it appears to me that i have the same setup with contact and location
>> but i am getting errors ??
>>
>> I think you forgot about "_set".
>> Try something like:
>>
>> Location.contact_set.all()
>>
>> And please don't use AutoField, db_column and primary_key until you have
>> a good reason. Also ForeignKey fetches an object of the connected type,
>> not an id, so "contactid", ... is confusing ;)
>>
>> --
>> Florian
>>
>> --
>> 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/559AB201.40600%40ist-total.org
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/YYM-cTEZOgA/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAJJc_8Vn72yWdFwUEFXRXD_4yOhD%2Bzx7n%3D0T189AsfGFU1n7Yg%40mail.gmail.com
> 
> .
>
> 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 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/CAH3cd3qiW0vKX_TxpmjuY5ZfVaVG2BPM1DK%2Byjt8Raw7-PrU0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models and relationships

2015-07-06 Thread Rafael E. Ferrero
contacts = Contacts.objects.select_related()

--
Rafael E. Ferrero

2015-07-06 13:51 GMT-03:00 Florian Schweikert :

> On 06/07/15 14:04, Chris Strasser wrote:
> > my problem is with reverse lookups (i think it is called) the docs say
> that i can access entries through blog.entry,(by lowercaseing the class)
> > it appears to me that i have the same setup with contact and location
> but i am getting errors ??
>
> I think you forgot about "_set".
> Try something like:
>
> Location.contact_set.all()
>
> And please don't use AutoField, db_column and primary_key until you have
> a good reason. Also ForeignKey fetches an object of the connected type,
> not an id, so "contactid", ... is confusing ;)
>
> --
> Florian
>
> --
> 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/559AB201.40600%40ist-total.org
> .
> 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 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/CAJJc_8Vn72yWdFwUEFXRXD_4yOhD%2Bzx7n%3D0T189AsfGFU1n7Yg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models and relationships

2015-07-06 Thread Florian Schweikert
On 06/07/15 14:04, Chris Strasser wrote:
> my problem is with reverse lookups (i think it is called) the docs say that i 
> can access entries through blog.entry,(by lowercaseing the class)
> it appears to me that i have the same setup with contact and location but i 
> am getting errors ??

I think you forgot about "_set".
Try something like:

Location.contact_set.all()

And please don't use AutoField, db_column and primary_key until you have
a good reason. Also ForeignKey fetches an object of the connected type,
not an id, so "contactid", ... is confusing ;)

--
Florian

-- 
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/559AB201.40600%40ist-total.org.
For more options, visit https://groups.google.com/d/optout.


Re: Models and relationships

2015-07-06 Thread Vijay Khemlani
Try with

Contact.objects.all()[0]

On Mon, Jul 6, 2015 at 1:03 PM, Chris Strasser 
wrote:

> I tried and this happens:
>
> from main.models import Contact
>
> >>> contact = Contact.all()[0]
>
> Traceback (most recent call last):
>
>   File "", line 1, in 
>
> AttributeError: type object 'Contact' has no attribute 'all'
>
> >>>
>
> ??
>
> any ideas ?
>
> On Mon, Jul 6, 2015 at 8:43 AM, Sadaf Noor  wrote:
>
>> If you have at least one entry in contact with a valid location, then it 
>> should work:
>>
>> from app.models import Contact
>>> contact = Contact.all()[0]
>>> print contact.locationid.locationname
>>
>>
>> 2015-07-06 18:04 GMT+06:00 Chris Strasser :
>>
>>> Hi ,I am fairly new to Django and am struggling with models hope someone 
>>> can sort me out.
>>>
>>>
>>> Models:
>>> class Organization(models.Model):  #customer or vendor person or company
>>> orgid = models.AutoField(db_column='OrgID', primary_key=True)
>>> is_company = models.NullBooleanField(db_column='IsCompany', default 
>>> =True)
>>> organizationname = models.CharField(db_column='OrgName', 
>>> max_length=75,blank=True, null=True)
>>> main_phone = models.CharField(db_column='MainPhone',max_length=20, 
>>> blank=True, null=True)
>>> ...
>>> ...
>>>
>>> class Location(models.Model):
>>> locationid = models.AutoField(db_column='LocationID', primary_key=True)
>>> orgid = models.ForeignKey(Organization, db_column='OrgID')
>>> locationname = models.CharField(db_column='LocationName', 
>>> max_length=75, null=True)
>>> address1 = models.CharField(db_column='Address1', max_length=200, 
>>> blank=True, null=True)
>>> ...
>>> ...
>>>
>>>  class Contact(models.Model):
>>> contactid = models.AutoField(db_column='ContactID', primary_key=True)
>>> locationid = models.ForeignKey(Location, db_column='LocationID')
>>> firstname = models.CharField(db_column='FirstName', 
>>> max_length=50,blank=True, null=True)
>>> lastname = models.CharField(db_column='LastName', 
>>> max_length=50,blank=True, null=True)
>>> ...
>>> ...
>>>
>>> my problem is with reverse lookups (i think it is called) the docs say that 
>>> i can access entries through blog.entry,(by lowercaseing the class)
>>> it appears to me that i have the same setup with contact and location but i 
>>> am getting errors ??
>>>
>>>
>>> what I am trying to do is access a contacts address and organization at 
>>> both the views level and the templates.(I would like to create a
>>> list of contacts, their company and their address ordered by contact name)
>>>
>>> if someone would point me in the right direction it would be greatly 
>>> appreciated.
>>>
>>> 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.
>>> 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/8abd757c-cd28-4c2f-82c9-ecd8c60dff4d%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>>   Md. Sadaf Noor (@sadaf2605 )
>>  www.sadafnoor.com
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/YYM-cTEZOgA/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/CAAJ2eVrtQ%2BpUkdW-OsAk0vQEHrWynwAAfOxQHtn%3D7xJ0AsEdHA%40mail.gmail.com
>> 
>> .
>>
>> 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 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/CAH3cd3oHiNtBXN%2BR8UwWvNR6GThV8WPbCt4myEQs1cupdXp-SQ%40mail.gmail.com
> 

Re: Models and relationships

2015-07-06 Thread Chris Strasser
I tried and this happens:

from main.models import Contact

>>> contact = Contact.all()[0]

Traceback (most recent call last):

  File "", line 1, in 

AttributeError: type object 'Contact' has no attribute 'all'

>>>

??

any ideas ?

On Mon, Jul 6, 2015 at 8:43 AM, Sadaf Noor  wrote:

> If you have at least one entry in contact with a valid location, then it 
> should work:
>
> from app.models import Contact
>> contact = Contact.all()[0]
>> print contact.locationid.locationname
>
>
> 2015-07-06 18:04 GMT+06:00 Chris Strasser :
>
>> Hi ,I am fairly new to Django and am struggling with models hope someone can 
>> sort me out.
>>
>>
>> Models:
>> class Organization(models.Model):  #customer or vendor person or company
>> orgid = models.AutoField(db_column='OrgID', primary_key=True)
>> is_company = models.NullBooleanField(db_column='IsCompany', default 
>> =True)
>> organizationname = models.CharField(db_column='OrgName', 
>> max_length=75,blank=True, null=True)
>> main_phone = models.CharField(db_column='MainPhone',max_length=20, 
>> blank=True, null=True)
>> ...
>> ...
>>
>> class Location(models.Model):
>> locationid = models.AutoField(db_column='LocationID', primary_key=True)
>> orgid = models.ForeignKey(Organization, db_column='OrgID')
>> locationname = models.CharField(db_column='LocationName', max_length=75, 
>> null=True)
>> address1 = models.CharField(db_column='Address1', max_length=200, 
>> blank=True, null=True)
>> ...
>> ...
>>
>>  class Contact(models.Model):
>> contactid = models.AutoField(db_column='ContactID', primary_key=True)
>> locationid = models.ForeignKey(Location, db_column='LocationID')
>> firstname = models.CharField(db_column='FirstName', 
>> max_length=50,blank=True, null=True)
>> lastname = models.CharField(db_column='LastName', 
>> max_length=50,blank=True, null=True)
>> ...
>> ...
>>
>> my problem is with reverse lookups (i think it is called) the docs say that 
>> i can access entries through blog.entry,(by lowercaseing the class)
>> it appears to me that i have the same setup with contact and location but i 
>> am getting errors ??
>>
>>
>> what I am trying to do is access a contacts address and organization at both 
>> the views level and the templates.(I would like to create a
>> list of contacts, their company and their address ordered by contact name)
>>
>> if someone would point me in the right direction it would be greatly 
>> appreciated.
>>
>> 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.
>> 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/8abd757c-cd28-4c2f-82c9-ecd8c60dff4d%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
>   Md. Sadaf Noor (@sadaf2605 )
>  www.sadafnoor.com
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/YYM-cTEZOgA/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAAJ2eVrtQ%2BpUkdW-OsAk0vQEHrWynwAAfOxQHtn%3D7xJ0AsEdHA%40mail.gmail.com
> 
> .
>
> 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 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/CAH3cd3oHiNtBXN%2BR8UwWvNR6GThV8WPbCt4myEQs1cupdXp-SQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models and relationships

2015-07-06 Thread Rafael E. Ferrero
For start you don't need to specify the primary key (orgid for example) [1]
In foreingkeys you need to use related names [2]

In views use select_related() [3]

[1] https://docs.djangoproject.com/en/1.8/ref/models/fields/#primary-key
[2] https://docs.djangoproject.com/en/1.8/ref/models/fields/#foreignkey
[3]
https://docs.djangoproject.com/en/1.8/ref/models/querysets/#select-related
--
Rafael E. Ferrero

2015-07-06 9:04 GMT-03:00 Chris Strasser :

> Hi ,I am fairly new to Django and am struggling with models hope someone can 
> sort me out.
>
>
> Models:
> class Organization(models.Model):  #customer or vendor person or company
> orgid = models.AutoField(db_column='OrgID', primary_key=True)
> is_company = models.NullBooleanField(db_column='IsCompany', default =True)
> organizationname = models.CharField(db_column='OrgName', 
> max_length=75,blank=True, null=True)
> main_phone = models.CharField(db_column='MainPhone',max_length=20, 
> blank=True, null=True)
> ...
> ...
>
> class Location(models.Model):
> locationid = models.AutoField(db_column='LocationID', primary_key=True)
> orgid = models.ForeignKey(Organization, db_column='OrgID')
> locationname = models.CharField(db_column='LocationName', max_length=75, 
> null=True)
> address1 = models.CharField(db_column='Address1', max_length=200, 
> blank=True, null=True)
> ...
> ...
>
>  class Contact(models.Model):
> contactid = models.AutoField(db_column='ContactID', primary_key=True)
> locationid = models.ForeignKey(Location, db_column='LocationID')
> firstname = models.CharField(db_column='FirstName', 
> max_length=50,blank=True, null=True)
> lastname = models.CharField(db_column='LastName', 
> max_length=50,blank=True, null=True)
> ...
> ...
>
> my problem is with reverse lookups (i think it is called) the docs say that i 
> can access entries through blog.entry,(by lowercaseing the class)
> it appears to me that i have the same setup with contact and location but i 
> am getting errors ??
>
>
> what I am trying to do is access a contacts address and organization at both 
> the views level and the templates.(I would like to create a
> list of contacts, their company and their address ordered by contact name)
>
> if someone would point me in the right direction it would be greatly 
> appreciated.
>
> 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.
> 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/8abd757c-cd28-4c2f-82c9-ecd8c60dff4d%40googlegroups.com
> 
> .
> 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 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/CAJJc_8XiTUaeXBwCwKuqO8L7gnX8muqWd7pjGchT0C_FnDVCQA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models and relationships

2015-07-06 Thread Sadaf Noor
If you have at least one entry in contact with a valid location, then
it should work:

from app.models import Contact
> contact = Contact.all()[0]
> print contact.locationid.locationname


2015-07-06 18:04 GMT+06:00 Chris Strasser :

> Hi ,I am fairly new to Django and am struggling with models hope someone can 
> sort me out.
>
>
> Models:
> class Organization(models.Model):  #customer or vendor person or company
> orgid = models.AutoField(db_column='OrgID', primary_key=True)
> is_company = models.NullBooleanField(db_column='IsCompany', default =True)
> organizationname = models.CharField(db_column='OrgName', 
> max_length=75,blank=True, null=True)
> main_phone = models.CharField(db_column='MainPhone',max_length=20, 
> blank=True, null=True)
> ...
> ...
>
> class Location(models.Model):
> locationid = models.AutoField(db_column='LocationID', primary_key=True)
> orgid = models.ForeignKey(Organization, db_column='OrgID')
> locationname = models.CharField(db_column='LocationName', max_length=75, 
> null=True)
> address1 = models.CharField(db_column='Address1', max_length=200, 
> blank=True, null=True)
> ...
> ...
>
>  class Contact(models.Model):
> contactid = models.AutoField(db_column='ContactID', primary_key=True)
> locationid = models.ForeignKey(Location, db_column='LocationID')
> firstname = models.CharField(db_column='FirstName', 
> max_length=50,blank=True, null=True)
> lastname = models.CharField(db_column='LastName', 
> max_length=50,blank=True, null=True)
> ...
> ...
>
> my problem is with reverse lookups (i think it is called) the docs say that i 
> can access entries through blog.entry,(by lowercaseing the class)
> it appears to me that i have the same setup with contact and location but i 
> am getting errors ??
>
>
> what I am trying to do is access a contacts address and organization at both 
> the views level and the templates.(I would like to create a
> list of contacts, their company and their address ordered by contact name)
>
> if someone would point me in the right direction it would be greatly 
> appreciated.
>
> 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.
> 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/8abd757c-cd28-4c2f-82c9-ecd8c60dff4d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
  Md. Sadaf Noor (@sadaf2605 )
 www.sadafnoor.com

-- 
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/CAAJ2eVrtQ%2BpUkdW-OsAk0vQEHrWynwAAfOxQHtn%3D7xJ0AsEdHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Models and relationships

2015-07-06 Thread Chris Strasser


Hi ,I am fairly new to Django and am struggling with models hope someone can 
sort me out. 


Models:
class Organization(models.Model):  #customer or vendor person or company
orgid = models.AutoField(db_column='OrgID', primary_key=True)  
is_company = models.NullBooleanField(db_column='IsCompany', default =True)
organizationname = models.CharField(db_column='OrgName', 
max_length=75,blank=True, null=True)
main_phone = models.CharField(db_column='MainPhone',max_length=20, 
blank=True, null=True) 
...
...
 
class Location(models.Model):
locationid = models.AutoField(db_column='LocationID', primary_key=True)  
orgid = models.ForeignKey(Organization, db_column='OrgID')  
locationname = models.CharField(db_column='LocationName', max_length=75, 
null=True)  
address1 = models.CharField(db_column='Address1', max_length=200, 
blank=True, null=True)  
...
...

 class Contact(models.Model): 
contactid = models.AutoField(db_column='ContactID', primary_key=True)  
locationid = models.ForeignKey(Location, db_column='LocationID')  
firstname = models.CharField(db_column='FirstName', 
max_length=50,blank=True, null=True)  
lastname = models.CharField(db_column='LastName', max_length=50,blank=True, 
null=True) 
...
...

my problem is with reverse lookups (i think it is called) the docs say that i 
can access entries through blog.entry,(by lowercaseing the class)
it appears to me that i have the same setup with contact and location but i am 
getting errors ??


what I am trying to do is access a contacts address and organization at both 
the views level and the templates.(I would like to create a 
list of contacts, their company and their address ordered by contact name)

if someone would point me in the right direction it would be greatly 
appreciated. 

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.
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/8abd757c-cd28-4c2f-82c9-ecd8c60dff4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.