?
Solved

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

Posted on 2015-01-21
5
Medium Priority
?
243 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 17

Accepted Solution

by:
gelonida earned 2000 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 17

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 17

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
There is a huge demand for CodeIgniter among the PHP web developers due to its dynamic features and benefits these days. It is one of most popular and agile open source PHP framework for creating robust web applications in PHP web development field.…
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 …
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.
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

770 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