Re: ForeignKey Field does not exist?

2014-03-13 Thread Shawn Milochik
On Thu, Mar 13, 2014 at 7:27 PM, wasingej wrote:

>
> When I go to grab information about the list with 'l =
> OwnerEntry(name='wasingej')', intuition would tell me that 'l' would be a
> list of entries with the name 'wasingej'.  However, when I try to access
> the value of 'l.list' django gives me this:
>
>
You want: records = OwnerEntry.objects.filter(name='wasingej')

-- 
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+unsubscr...@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/CAOzwKwG_yppdZqFuNR_TOtR_a8Ak6k753cU5pH4W-h3EfFKZOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


ForeignKey Field does not exist?

2014-03-13 Thread wasingej
I am trying to develop a web interface in Django which manages email 
lists.  In one table, ListEntry, I have entries containing information 
about lists.  In another table, OwnerEntry, I have information about list 
owners.  Each entry in the OwnerEntry table has the username of a list 
owner, and a ForeignKey to the list that owner administrates.  An owner can 
administrate multiple lists meaning that there could be entries in the 
OwnerEntry table with the same owner name but different ForeignKeys 
pertaining to different lists.

Here is models.py:

class ListEntry(models.Model):
name = models.CharField(max_length=64)
date = models.DateTimeField('date created')

class Meta:
ordering = ('name',)

class OwnerEntry(models.Model):
name = models.CharField(max_length=32)
list = models.ForeignKey(ListEntry)

class Meta:
ordering = ('name',)

I am trying to test this setup out in the shell and initiallize my local 
database with the following code:

from list_app.models import *
from datetime import *

le1 = ListEntry(
name = "Physics 211 email list",
date = datetime.now(),
)
le1.save()

le2 = ListEntry(
name = "Physics 265 email list",
date = datetime(2014,1,1),
)
le2.save()

oe1 = OwnerEntry(
name = 'wasingej',
list = le1,
)
oe1.save()

oe2 = OwnerEntry(
name = 'wasingej',
list = le2,
)
oe2.save()

oe3 = OwnerEntry(
name = 'doej',
list = le2,
)
oe3.save()

When I go to grab information about the list with 'l = 
OwnerEntry(name='wasingej')', intuition would tell me that 'l' would be a 
list of entries with the name 'wasingej'.  However, when I try to access 
the value of 'l.list' django gives me this:

Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", 
line 324, in __get__
"%s has no %s." % (self.field.model.__name__, self.field.name))
DoesNotExist: OwnerEntry has no list.

What am I doing wrong here?

-- 
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+unsubscr...@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/54a3d6d7-58f6-4f97-b1ee-d8f18516b405%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.