Test the "contact.contactnumber_set.all" in a shell, I'm not sure 100% sure on the syntax
On Fri, Nov 18, 2016 at 11:51 AM, 'David Turner' via Django users < [email protected]> wrote: > Thankyou for this, although for some reason it does not work. > What other infromation would you need to further advise me. > Thanks > > On 18 November 2016 at 13:42, Vijay Khemlani <[email protected]> wrote: > >> In your model a contact may have multiple phone numbers (multiple >> Contactnumber instances with foreign key to the same Contact instance) so >> your question is a bit vague. >> >> If you wanted to list all numbers for a given contact you could do >> somethinkg like >> >> <td>{% for contact in practice.contacts.all %} >> {{ contact }} >> <ul> >> {% for contactnumber in contact.contactnumber_set.all %} >> <li>{{ contactnumber.phone_number }}</li> >> {% endfor %} >> </ul> >> {% endfor %}</td> >> >> >> On Fri, Nov 18, 2016 at 9:08 AM, 'dtdave' via Django users < >> [email protected]> wrote: >> >>> As still learning django I have a simple issue. >>> >>> I have the following models: >>> >>> >>> class Contactnumber(TimeStampedModel): >>> phone_number = models.CharField(max_length=100, unique=True) >>> contact = models.ForeignKey(‘contacts.Contact') >>> >>> >>> >>> class Contact(TimeStampedModel): >>> contact = models.CharField(max_length=100, db_index=True, >>> verbose_name='Contact Name') >>> practice = models.ManyToManyField(‘practice.Practice’, >>> related_name=“contacts",) >>> >>> >>> >>> class Practice(TimeStampedModel): >>> practice = models.CharField(max_length=150, db_index=True, >>> verbose_name='Practice Name', >>> help_text="include location for >>> multi-branch”) >>> >>> >>> >>> I have a template including data tables in which I want to show the >>> following: >>> Practice, Contact, Contact Phone >>> >>> The following gives me the contact for the practice: >>> <td>{% for contact in practice.contacts.all %} >>> {{ contact }} >>> {% endfor %}</td> >>> >>> My question is how do include the contact phone number as I seem a bit >>> lost. >>> Any help would be appreciated. Apologies if this is a simple question! >>> >>> -- >>> 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 https://groups.google.com/group/django-users. >>> To view this discussion on the web visit https://groups.google.com/d/ms >>> gid/django-users/0d8490a2-db29-435a-9477-e26dfa03c560%40googlegroups.com >>> <https://groups.google.com/d/msgid/django-users/0d8490a2-db29-435a-9477-e26dfa03c560%40googlegroups.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 a topic in the >> Google Groups "Django users" group. >> To unsubscribe from this topic, visit https://groups.google.com/d/to >> pic/django-users/iGLMpw_nkac/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit https://groups.google.com/d/ms >> gid/django-users/CALn3ei1oYxPDBu1uWK1KGafY55s-ftHA-t_ >> cNqNUbM-oSGYpKA%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CALn3ei1oYxPDBu1uWK1KGafY55s-ftHA-t_cNqNUbM-oSGYpKA%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 https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/CALwQ%2B-t3VO2u8X7VyNgKSGbuJArL8U01zQjz > 1zP-n2bDjhkfqQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CALwQ%2B-t3VO2u8X7VyNgKSGbuJArL8U01zQjz1zP-n2bDjhkfqQ%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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei2cN3vK3qtWgRfC0C2o1jvx2n3Xsfcxu5safnrL5s94iw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

