Tuesday, June 2, 2015

Re: new to Django having models/views/templates question

Can you post the error and traceback? It sounds like you may have an encoding issue.

-James

On Jun 2, 2015 11:00 AM, "Chris Strasser" <cstrasser11@gmail.com> 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+unsubscribe@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/76ad4dab-574e-4867-96b6-96be02e8a739%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+unsubscribe@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%2BciUCqh8uCqSA9JNh18XUWO8FfDnjpCS5V_5ksNXoT6VqOg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment