Solved

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

Posted on 2015-01-21
5
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.

730 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