Re: How to select all the values from my Field attribute 'choices?

2007-11-27 Thread äL

How can I get all values of my "choices"?

I have a template which contains an drop-down-list with all values.
The drop-down-list
has several entries but unfortunatelly only the same. In my choices-
list
I have 5 entries. And in the drop-down-list 5 entries, too (But the
same).

How can I get all values?
From a table it's easy:
Just type "nations   = Country.objects.all()"
With a choice-list "objects.all()" doesn't work.



äL


On 8 Nov., 13:42, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On 11/8/07, äL <[EMAIL PROTECTED]> wrote:
>
> > Do I have an error in the import syntax? How can I import ROLE?
>
> You don't. Just import Karateka and use Karateka.ROLE.
>
> -Gul
--~--~-~--~~~---~--~~
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: How to select all the values from my Field attribute 'choices?

2007-11-08 Thread Marty Alchin

On 11/8/07, äL <[EMAIL PROTECTED]> wrote:
> Do I have an error in the import syntax? How can I import ROLE?

You don't. Just import Karateka and use Karateka.ROLE.

-Gul

--~--~-~--~~~---~--~~
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: How to select all the values from my Field attribute 'choices?

2007-11-08 Thread äL

Hi,

If I try to import ROLE I get an the error "cannot import name ROLE"

views.py
### CODE ###
def Karateka_edit(request, karateka_id):

from kav.info.models import Karateka, ROLE

roles= [y for x,y in ROLE]

try:
karateka  = Karateka.objects.get(id = karateka_id)
except Karateka.DoesNotExist:
raise Http404
return render_to_response('info_karateka_edit.html', {
 'karateka'  : karateka,
 'roles'   : roles,
 'user'  : request.user})
### END CODE ###

Here is my models.py
### CODE ###
class Karateka(models.Model):
ROLE = (
('1', 'Sportler'),
('2', 'Nachwuchsteam A'),
('3', 'Nachwuchsteam B'),
('4', 'Funktionär'),
('5', 'Trainer'),
)
person= models.ForeignKey   (Person,verbose_name = 'Person',
core = True)
role  = models.CharField('Funktion',blank = True, null =
True, maxlength = 1, choices=ROLE)

def __str__(self):
return "%s" % (self.person)

class Admin:
list_display = ('person')
fields = (
(None,   {'fields': ('person', 'bsc')}),
)

def name_last(self):
return "%s" % (self.person.nameLast)

class Meta:
ordering = ('person',)
verbose_name= 'Karateka'
verbose_name_plural = 'Karatekas'

### END CODE ###

Do I have an error in the import syntax? How can I import ROLE?

Thanks for your help
regards,
äL


On 6 Nov., 21:27, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On 11/6/07, äL <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hello Karen
>
> > I have the same problem as Greg has.
>
> > If I try to use your code I got an "page not found" error.
> > Here is my code:
>
> > views.py
> > ### CODE ###
> > def Karateka_edit(request, karateka_id):
>
> > from kav.info.models import Karateka
>
> > try:
> > karateka  = Karateka.objects.get(id = karateka_id)
> > roles= [y for x,y in ROLE]
> > except Karateka.DoesNotExist:
> > raise Http404
> > return render_to_response('info_karateka_edit.html', {
> >  'karateka'  : karateka,
> >  'roles'   : roles,
> >  'user'  : request.user})
> > ### END CODE ###
>
> > Do I need to import ROLE like Karateka or do I have an other error in
> > my code?
>
> Yes, assuming ROLE is defined in your models file you will need to import it
> when you want to use it from another file.  But that is not why you got a
> 404 (page not found).  Given that code, you'd only get a 404 if the
> Karateka.objects.get call raises Karateka.DoesNotExist.  So you didn't even
> get as far as the roles= line (there's no reason to include that in the
> try/except btw).  If you had gotten as far as the roles= line and if you had
> not imported ROLE from wherever it is defined, you would have gotten a
> NameError "Global name ROLE is not defined".
>
> Karen


--~--~-~--~~~---~--~~
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: How to select all the values from my Field attribute 'choices?

2007-11-06 Thread Karen Tracey
On 11/6/07, äL <[EMAIL PROTECTED]> wrote:
>
>
> Hello Karen
>
> I have the same problem as Greg has.
>
> If I try to use your code I got an "page not found" error.
> Here is my code:
>
> views.py
> ### CODE ###
> def Karateka_edit(request, karateka_id):
>
> from kav.info.models import Karateka
>
> try:
> karateka  = Karateka.objects.get(id = karateka_id)
> roles= [y for x,y in ROLE]
> except Karateka.DoesNotExist:
> raise Http404
> return render_to_response('info_karateka_edit.html', {
>  'karateka'  : karateka,
>  'roles'   : roles,
>  'user'  : request.user})
> ### END CODE ###
>
> Do I need to import ROLE like Karateka or do I have an other error in
> my code?


Yes, assuming ROLE is defined in your models file you will need to import it
when you want to use it from another file.  But that is not why you got a
404 (page not found).  Given that code, you'd only get a 404 if the
Karateka.objects.get call raises Karateka.DoesNotExist.  So you didn't even
get as far as the roles= line (there's no reason to include that in the
try/except btw).  If you had gotten as far as the roles= line and if you had
not imported ROLE from wherever it is defined, you would have gotten a
NameError "Global name ROLE is not defined".

Karen

--~--~-~--~~~---~--~~
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: How to select all the values from my Field attribute 'choices?

2007-11-06 Thread äL

Hello Karen

I have the same problem as Greg has.

If I try to use your code I got an "page not found" error.
Here is my code:

views.py
### CODE ###
def Karateka_edit(request, karateka_id):

from kav.info.models import Karateka

try:
karateka  = Karateka.objects.get(id = karateka_id)
roles= [y for x,y in ROLE]
except Karateka.DoesNotExist:
raise Http404
return render_to_response('info_karateka_edit.html', {
 'karateka'  : karateka,
 'roles'   : roles,
 'user'  : request.user})
### END CODE ###

Do I need to import ROLE like Karateka or do I have an other error in
my code?
Regards,
äL

On 24 Okt., 00:06, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On 10/23/07, Greg <[EMAIL PROTECTED]> wrote:
> [snip]
>
> > class Collection(models.Model):
>
> > THE_MATERIAL = (
> > ('1', 'Paper'),('2', 'Plastic'),('3', 'Other'),
> > )
>
> > material = models.CharField(max_length=50, choices=THE_MATERIAL)
>
> > ///
>
> > However, now I want to be able to do a query that returns all of the
> > values in THE_MATERIAL (even if it's not being used by any
> > collection).  How would the query be setup to do this?
>
> Well, you can't set up a query for something that isn't in the database.
> But the values are right there in THE_MATERIAL.  If you want a list of just
> the text values, stripping away the numeric choices, some simple Python:
>
> material_list = [y for x,y in THE_MATERIAL]
>
> would do it.
>
> Karen


--~--~-~--~~~---~--~~
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: How to select all the values from my Field attribute 'choices?

2007-10-23 Thread Karen Tracey
On 10/23/07, Greg <[EMAIL PROTECTED]> wrote:
[snip]

> class Collection(models.Model):
>
> THE_MATERIAL = (
> ('1', 'Paper'),('2', 'Plastic'),('3', 'Other'),
> )
>
> material = models.CharField(max_length=50, choices=THE_MATERIAL)
>
> ///
>
> However, now I want to be able to do a query that returns all of the
> values in THE_MATERIAL (even if it's not being used by any
> collection).  How would the query be setup to do this?


Well, you can't set up a query for something that isn't in the database.
But the values are right there in THE_MATERIAL.  If you want a list of just
the text values, stripping away the numeric choices, some simple Python:

material_list = [y for x,y in THE_MATERIAL]

would do it.

Karen

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



How to select all the values from my Field attribute 'choices?

2007-10-23 Thread Greg

Hello,
When I first developed my application I created a table that stored
all the different types of materials

class Material(models.Model):
material = models.CharField(maxlength=100)

To get all the materials in the table all I needed to do was query the
table.  Recently, I've been going through my code to see if I can
clean it up.  So I deleted my table Material and made it into a
'choices' attribute.  So now I have

class Collection(models.Model):

THE_MATERIAL = (
('1', 'Paper'),('2', 'Plastic'),('3', 'Other'),
)

material = models.CharField(max_length=50, choices=THE_MATERIAL)

///

However, now I want to be able to do a query that returns all of the
values in THE_MATERIAL (even if it's not being used by any
collection).  How would the query be setup to do this?

Thanks


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