Tuesday, December 3, 2013

Re: How to integrate Postgresql db with Django,so that data will be retrieved from that postgresql db table and show it on browser via html

in the mean time i was able to populate datas's from postgres table by modifying the models.py and views.py as follows::

urls.py
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'mysite.views.home', name='home'),
    url(r'^blisteddevies/$', 'mysite.views.blisteddevies', name='blisteddevies'),
    url(r'^admin/', include(admin.site.urls)),
)

Models.py:
from __future__ import unicode_literals

from django.db import models


class DeviceTable(models.Model):
    serial_no = models.IntegerField()
    macid = models.CharField(max_length=100, primary_key=True)
    class Meta:
        db_table = 'device_table'

VIEWS.py::
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.shortcuts import render
from app.models import DeviceTable



def home(request):
    rows = DeviceTable.objects.all()
    data = []
    for row in rows:
        data.append(row.macid)
        
    return render_to_response('app/home.html', {'data':data})

def blisteddevies(request):
    return render_to_response(
    'app/blisteddevies.html',
    )

and in app folder i hav created admin.py::

from django.contrib import admin
from app.models import DeviceTable

admin.site.register(DeviceTable)



NOW what i require is :if i select tick button against that macid to be blacklisted and click on save it should save it to postgres database table and also show it on the blacklisted page when i access blacklisted.html page via django.
Please guide me and i have also attached some screenshots for better idea of scenario.

Thank you

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/74d2cfef-6667-4a1e-90a8-aabce7bbe76d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate