I'm trying to do a bit of simple Django access to a postgresql
database, and must be missing something. Using the tutorial info, I've
had mixed success.   I can pull a bit of stuff form the database, but
have some curious behaviour that is slowing me down.  See the example
details below...

Problems:
a) I am able to get an SList object by specifying the id, but the .id
attribute is not accessible.
If I use the django shell, it behaves as expected, but not when
implemented in my views.py

b) I could not create and save a new object in my database, so I tried
it in the interactive shell where it worked as expected, then upon
trying it again in with the dev server running, and executing the
populateDB in views below, it worked.
However, I can only create an SList object by explicitly specifying
the id= field.  It should allow me to make one without specifying
that  (see doghop example below).

Am I missing something?  This seems very non-functional, so it must be
me.


>>>>>My models.py file contains a model:

class SList(models.Model):
    def __str__(self):
        return self.SListName
    SListName = models.CharField(maxlength=16)      # opportunity to
group sports
    class Admin:
        pass

>>>> And my views.py file:

from myproject.trial.models import SList
def populateDB(request):

    print('PopDB called successfully')
    sl1 = SList.objects.get(id=1)
    print('try a get: ' + sl1.SListName)                #this works fine

    print('id: ' + sl1.id)                              #this won't work (see a)

    s = SList(id=5, SListName='monkeyjump')     #worked only after
interactive session
    s.save()

    t = SList(SListName='doghop')                       #doesn't work (see b)
    t.save()

return null

I'd appreciate any guidance on what I'm missing...

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to