Re: something I really don't know in using manage.py shell

2007-08-02 Thread oggie rob

Yes. "filter" returns a set (hence the [] around "",
indicating a collection). If you are using a pk, where you can
guarantee a single returned value, use "get":
>>> p = Profile.objects.get(id=1)
>>> p.department

 -rob

On Aug 1, 10:35 pm, james_027 <[EMAIL PROTECTED]> wrote:
> hi,
>
> i am trying to use the manage.py shell, for fast testing of what I
> would like to do.
>
> I have a model like this
>
> class Function(models.Model):
> """Functions that KSK Employee account could use"""
>
> name = models.CharField(maxlength=40)
> url = models.CharField(maxlength=40, default='/')
> method = models.CharField(maxlength=40, default='index')
>
> class Profile(models.Model):
> """KSK Employee accounts to use this application"""
>
> user = models.ForeignKey(User, unique=True)
> department = models.CharField(maxlength=3,
> choices=DEPARTMENT_LIST)
> level = models.CharField(maxlength=2, choices=LEVEL_LIST)
> functions = models.ManyToManyField(Function, blank=True)
>
> when I do in the shell
>
> >>>p = Profile.objects.filter(id=1)
> >>>p
>
> []
> but when I did this>>>p.department
>
> it say
> AttributeError: '_QuerySet' object has no attribute 'level'
>
> is there anything I should know?
>
> THanks
> james


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: something I really don't know in using manage.py shell

2007-08-02 Thread Lucky B

You should be doing
>>> p = Profile.objects.get(id=1)#or .get(1) or one of the many other 
>>> posibilities

filter returns a list of the results, in the case of id=# it probably
returns only one, but it's still a list of one member.

So in your case it would work if you did this:
>>>p= Profile.objects.filter(id=1)
>>>print p[0]

On Aug 2, 1:35 am, james_027 <[EMAIL PROTECTED]> wrote:
> hi,
>
> i am trying to use the manage.py shell, for fast testing of what I
> would like to do.
>
> I have a model like this
>
> class Function(models.Model):
> """Functions that KSK Employee account could use"""
>
> name = models.CharField(maxlength=40)
> url = models.CharField(maxlength=40, default='/')
> method = models.CharField(maxlength=40, default='index')
>
> class Profile(models.Model):
> """KSK Employee accounts to use this application"""
>
> user = models.ForeignKey(User, unique=True)
> department = models.CharField(maxlength=3,
> choices=DEPARTMENT_LIST)
> level = models.CharField(maxlength=2, choices=LEVEL_LIST)
> functions = models.ManyToManyField(Function, blank=True)
>
> when I do in the shell
>
> >>>p = Profile.objects.filter(id=1)
> >>>p
>
> []
> but when I did this>>>p.department
>
> it say
> AttributeError: '_QuerySet' object has no attribute 'level'
>
> is there anything I should know?
>
> THanks
> james


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: something I really don't know in using manage.py shell

2007-08-02 Thread johan de taeye


I suspect you get this error because "level" is a reserved keyword in
many databases.
Try renaming the field.

Johan


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



something I really don't know in using manage.py shell

2007-08-01 Thread james_027

hi,

i am trying to use the manage.py shell, for fast testing of what I
would like to do.

I have a model like this

class Function(models.Model):
"""Functions that KSK Employee account could use"""

name = models.CharField(maxlength=40)
url = models.CharField(maxlength=40, default='/')
method = models.CharField(maxlength=40, default='index')

class Profile(models.Model):
"""KSK Employee accounts to use this application"""

user = models.ForeignKey(User, unique=True)
department = models.CharField(maxlength=3,
choices=DEPARTMENT_LIST)
level = models.CharField(maxlength=2, choices=LEVEL_LIST)
functions = models.ManyToManyField(Function, blank=True)

when I do in the shell

>>>p = Profile.objects.filter(id=1)
>>>p
[]
but when I did this
>>>p.department
it say
AttributeError: '_QuerySet' object has no attribute 'level'

is there anything I should know?

THanks
james


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---