Posting the actual model code will probably help. Your template has this:
item.customer_location.name But you specified the issue later as this: item.customer_location.customer The former won't work per your summarized model definitions. The Location model has no attribute called 'name'. The latter will work only if your __str__() function is encoding the data correctly. The reason you are getting a recursion error is because of the 'unicode(self)' (which I'm assuming is part of your model's __str__() definition). You need to change that to something like unicode(self.name). I'm not even sure if the unicode() call is even necessary (haven't done a ton of Python 3 yet). As far as referring to the Customer name, you can do {{ item.customer_location.customer.name }} Have you thought about tying in the customer directly to the service order? It shouldn't be an issue to have a customer tied to both the location and the service order. While it'll work the way you have it, your lookups will become more complicated (and expensive from a processing perspective) since you are forcing a lookup across multiple tables. It may not agree with your business process, though. Just a thought. -James On Jun 2, 2015 11:57 AM, "Chris Strasser" <cstrasse...@gmail.com> wrote: > Hi James thanks for the response... > > > this line: <td>{{item.customer_location.customer}}</td> > > ..... worked this morning and all last week now gives this error: > > RuntimeError at /sto/ > > maximum recursion depth exceeded while calling a Python object > > Request Method: GET Request URL: http://10.0.0.102:8080/sto/ Django > Version: 1.8 Exception Type: RuntimeError Exception Value > > > > > maximum recursion depth exceeded while calling a Python object > > > I can reproduce the encoding error but i forget how to get there at the > moment ... > > > > > > On Tuesday, June 2, 2015 at 2:00:22 PM UTC-4, Chris Strasser wrote: >> >> Hi am plugging away at learning Django and have done well so far (thanks >> to great documentation and Stackoverflow) but I have run into a problem >> that i cant seem to figure out. >> >> >> I have a model that refers to another model that refers to another model. >> >> example : >> >> Class ServiceOrder >> id -integer >> customer location = foreign key to location >> >> def __str__(self): >> return self.stid >> >> class Location: >> id -integer >> address -char >> customer- foreign key to customer >> >> q= '%s %s %s %s ' %(self.addr1, self.addr2, self.city, >> self.country) >> return unicode(q).encode('utf-8') >> >> Class Customer >> id=int >> name- char >> return unicode(self).encode('utf-8') >> >> I have a template that lists the service orders view is below: >> >> >> def serviceorder_list(request, status = 'Closed'): >> ist = ServiceOrder.objects.filter(status = status, >> stid__lte=20239).select_related('customer_location__customer') >> #stid__lte 20239 to fix database error ... i have existing data that has >> its own issues... >> count = order_list.count() >> context ={'list': sto_list, 'count': count} >> >> return render(request, 'order/listview.html', context) >> >> >> in my listview.html >> >> {% for item in list %} >> {% if item.project %} >> <td><a href="{{ item.stid }}">{{item.stid}}</a></td> >> <td>{{item.project}}</td> >> <td>{{item.customer_location.name}}</td> >> ---------------------- 2 questions here 1) it throws an error on customer >> names that have accents etc ... >> >> <td>{{item.notes}}</td> >> 2) i am confused about how to properly referenece the >> customer name or anything else that is not in the Service order model. >> >> <td>{{item.person_responsible}}</td> >> <td>{{item.entrydate|date:'M-d-y'}}</td> >> <td>{{item.status}}</td> >> <td>{{item.billing}}</td> >> </tr> >> >> >> I have read the docs many times and the more i read the more i know that >> i don't know ... any help would be 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/bd0e074b-f45e-404b-87c7-919c2176d2dc%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/bd0e074b-f45e-404b-87c7-919c2176d2dc%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 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/CA%2Be%2BciUY1dFyCTD7PeJsVDiqnzLdEXeqOe1bHOgLuCjeyMjV4g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.