Solved

Access record sets in a Postgresql DB from Django - nothing appearing

Posted on 2015-01-21
5
184 Views
Last Modified: 2015-01-26
I am really sorry to be asking this but when I can't understand why I can't print my records out to the webpage.

Models.py:
from __future__ import unicode_literals

from django.db import models


class Facilities(models.Model):
    name = models.TextField(db_column='Name')  # Field name made lowercase.
    address = models.TextField(db_column='Address')  # Field name made lowercase.
    city = models.TextField(db_column='City')  # Field name made lowercase.
    postcode = models.TextField(db_column='Postcode')  # Field name made lowercase.
    price = models.TextField(db_column='Price')  # Field name made lowercase.
    id = models.IntegerField(db_column='ID', primary_key=True)  # Field name made lowercase.

    def __unicode__(self):
        return self

    class Meta:
        managed = False
        db_table = 'Facilities'

views.py:
from django.views.generic import ListView
from daypass.models import Facilities

class FL(ListView):
    model = Facilities

urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from daypass.views import FL
urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'recharge.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^daypass/$', FL.as_view()),

facilities_list.html
{% block content %}
    <h2>Facilities</h2>
    <ul>
        This loops:
        {% for e in object_list %}
            <li>
                {{ facilities.id }}</li>
        {% endfor %}
    </ul>
{% endblock %}

I just a load of bullets going down the page to presumably there is a record set but it isn't printing out to the page. I have tried different field names including in this example the ID field in case it was something to do with the way I am storing text in a textfield.

Where have I gone wrong?

thanks
0
Comment
Question by:lz7cjc
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
gelonida earned 500 total points
ID: 40562430
I don't have time to test and I never used Listview, but I think it's probably just a simple typo:

probably you wanted to write

{% for e in object_list %}
            <li>
                {{ e.id }}</li>
        {% endfor %}

Open in new window



instead of

{% for e in object_list %}
            <li>
                {{ facilities.id }}</li>
        {% endfor %}

Open in new window

0
 

Author Comment

by:lz7cjc
ID: 40562582
so near! thanks
0
 
LVL 16

Expert Comment

by:gelonida
ID: 40563844
So does it work now?
Or do you have another error message?
0
 

Author Comment

by:lz7cjc
ID: 40563846
Yes it works...thanks
How do you access records of you don't use list view? Is there a better way?
Thanks
0
 
LVL 16

Expert Comment

by:gelonida
ID: 40563855
No there's not a better way, just different ones.

The template would look probably identical.
Views can be classes or methods. the way you code is definitely more compact than my 'old style' coding. I just forget that all these classes exist ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now