Solved

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

Posted on 2015-01-21
5
172 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
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 strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now