I have the following Django Model which retrieves 3 records from a database. The class below represents a Model within a Django application I'm building. I realize that the parameters taken in by the create_hotspots
function are not being used. I just simplified what the code looked like previously for the purposes of explaining my problem.
from django.db import models
from django.db import connection, transaction
import math
import MySQLdb
class Victims(models.Model):
def __init__(self):
self.results=[]
def create_hotspots(self,radius,latitude,longitude):
self.radius=str(radius)
self.latitude=str(latitude)
self.longitude=str(longitude)
db=MySQLdb.connect (host = "localhost", user = "root",passwd = "pass",db = "test")
cursor = db.cursor ()
cursor.execute("""SELECT * FROM poi_table""")
self.results=cursor.fetchall()
cursor.close ()
db.close ()
def __unicode__(self):
return self.results
Now, assume that I open the Django shell and I execute the following instructions:
>>from PyLayar.layer.models import Victims
C:\Python26\lib\site-packages\MySQLdb\__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
>>> v=Victims()
>>> v.create_hotspots(1000, 42.3931955679, -72.5289916992)
>>> Victims.objects.all()
[]
My question is why does the Victims.objects.all()
instruction return no results. The SQL query returns 3 results, and the results
variable stores the resulting tuple.