[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

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

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
lz7cjc
Asked:
lz7cjc
  • 3
  • 2
1 Solution
 
gelonidaCommented:
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
 
lz7cjcAuthor Commented:
so near! thanks
0
 
gelonidaCommented:
So does it work now?
Or do you have another error message?
0
 
lz7cjcAuthor Commented:
Yes it works...thanks
How do you access records of you don't use list view? Is there a better way?
Thanks
0
 
gelonidaCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now