Re: Django Admin does not use `get_FOO_display`

2023-04-05 Thread Opeoluwa Fatunmbi
The reason why your overridden get_status_display method is not being
applied in the Django admin is because the admin's display_for_field
function uses the flatchoices attribute of the field to retrieve the
display value of the field's current value.

The flatchoices attribute is a list of two-tuples that represent the
choices available for the field, flattened into a single list. The first
element of each tuple is the value, and the second element is the display
string. The display_for_field function uses the flatchoices list to
retrieve the display value of the current value, rather than calling the
field's get_FOO_display method.

To make use of your overridden get_status_display method in the admin, you
can set the flatchoices attribute of the field to None or remove the
attribute altogether. This will cause the admin to call the
get_status_display method instead of the display_for_field function.


class MyModelAdmin(admin.ModelAdmin): form = MyModelForm class
MyModelForm(forms.ModelForm): class Meta: model = MyModel fields =
'__all__' def __init__(self, *args, **kwargs): super().__init__(*args,
**kwargs) # Remove the flatchoices attribute of the status field
self.fields['status'].flatchoices = None

In this example, we're creating a MyModelForm that is used in the
MyModelAdmin. We're overriding the __init__ method of the form to remove
the flatchoices attribute of the status field, which will cause the admin
to call the get_status_display method instead.










On Tue, 4 Apr 2023 at 17:43, 'Ibrahim Abou Elenein' via Django users <
django-users@googlegroups.com> wrote:

> I had a model having a field that uses Choices
> status = FSMField(default=STATUSES.PENDING, choices=STATUSES,
> protected=True)
>
> I did override  the `get_status_display ` and its effect was not applied
> in the Django admin
>
> I looked up Django code and found
> ```
> def display_for_field(value, field, empty_value_display): from
> django.contrib.admin.templatetags.admin_list import _boolean_icon if
> getattr(field, "flatchoices", None): return
> dict(field.flatchoices).get(value, empty_value_display)
> ``` I changed it to use get_FOO_display and it worked,
> my question is why does it have this behavior? and how in my application
> can I make use of this?
>
> Thank you.
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7dabd818-4b70-409e-8af3-482deb3an%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7dabd818-4b70-409e-8af3-482deb3an%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKVBneK9A4QZ72ibUzyHc60SsE6GY4Z7Gua29KObj9m-R%3DVLrA%40mail.gmail.com.


Django Admin does not use `get_FOO_display`

2023-04-04 Thread 'Ibrahim Abou Elenein' via Django users
I had a model having a field that uses Choices 
status = FSMField(default=STATUSES.PENDING, choices=STATUSES, 
protected=True)

I did override  the `get_status_display ` and its effect was not applied in 
the Django admin  

I looked up Django code and found 
```
def display_for_field(value, field, empty_value_display): from 
django.contrib.admin.templatetags.admin_list import _boolean_icon if 
getattr(field, "flatchoices", None): return 
dict(field.flatchoices).get(value, empty_value_display)
``` I changed it to use get_FOO_display and it worked, 
my question is why does it have this behavior? and how in my application 
can I make use of this?

Thank you.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7dabd818-4b70-409e-8af3-482deb3an%40googlegroups.com.


Re: get_FOO_display not working ?

2020-02-23 Thread Yves de Champlain
Hi

I’ll know if it is much help if it solves my problem. I’ll have a look into 
that.

Thanks !

yves


> Le 23 févr. 2020 à 02:32, Mike Dewhirst  a écrit :
> 
> Maybe the choices should be
> 
> STATUS = [
> ('draft', _('Draft')),
> ...
> ]
> 
> I think the migration system might detect a change in the model every time it 
> is run because the get_text_lazy() function can return a non-static result. 
> Not sure about that.
> 
> I haven't used _() myself but I have used methods to fill up choices lists 
> with just that outcome. I had to finalize the list prior to running migrate.
> 
> Not much help I know
> 
> Good luck
> 
> Mike
> 
>  Original message 
> From: Yves de Champlain 
> Date: 23/2/20 15:47 (GMT+10:00)
> To: Django users 
> Subject: get_FOO_display not working ?
> 
> Hi
> 
> I'm using StatusModel from models_utils :
> 
> class MetaData(TimeStampedModel, StatusModel, SoftDeletableModel):
> STATUS = Choices(('draft', _('Draft')),
>  ('submitted', _('Submitted')),
>  ('underreview', _('Underreview')),
>   )
> 
> Forms using STATUS work as expected, but when I load an object from the DB, I 
> can't access the human readable data in my templates.
> 
> a.status => draft
> a.get_status_display => draft
> 
> instead of
> 
> a.status => draft
> a.get_status_display => Draft
> 
> Thanks for any hep on this !
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/d7a06913-39a8-4e55-9799-ebc46cb5cde4%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/d7a06913-39a8-4e55-9799-ebc46cb5cde4%40googlegroups.com?utm_medium=email_source=footer>.
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/5e522a9f.1c69fb81.cae91.b7f5SMTPIN_ADDED_MISSING%40gmr-mx.google.com
>  
> <https://groups.google.com/d/msgid/django-users/5e522a9f.1c69fb81.cae91.b7f5SMTPIN_ADDED_MISSING%40gmr-mx.google.com?utm_medium=email_source=footer>.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/377B8ADD-1C7A-4418-BA76-3A12C325DC44%40gmail.com.


Re: get_FOO_display not working ?

2020-02-23 Thread Yves de Champlain
Hi

Actually, the human readable value is not (‘Draft’) but _(‘Draft’) which is 
shorthand for gettext_lazy(‘Draft’)

Yves


> Le 22 févr. 2020 à 23:54, Nde Nguti  a écrit :
> 
> CHOICES =(('draft', 'Draft'), )
> 
> On Sun, Feb 23, 2020, 05:48 Yves de Champlain  > wrote:
> Hi
> 
> I'm using StatusModel from models_utils :
> 
> class MetaData(TimeStampedModel, StatusModel, SoftDeletableModel):
> STATUS = Choices(('draft', _('Draft')),
>  ('submitted', _('Submitted')),
>  ('underreview', _('Underreview')),
>   )
> 
> Forms using STATUS work as expected, but when I load an object from the DB, I 
> can't access the human readable data in my templates.
> 
> a.status => draft
> a.get_status_display => draft
> 
> instead of
> 
> a.status => draft
> a.get_status_display => Draft
> 
> Thanks for any hep on this !
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/d7a06913-39a8-4e55-9799-ebc46cb5cde4%40googlegroups.com
>  
> .
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CALfkE84BbTc47u0TGL_PWYNXpoXjs0rsZUG4rjSBNySd8SLGyw%40mail.gmail.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C1C43B13-5D76-4C44-9979-F6D9E12D5F6F%40gmail.com.


RE: get_FOO_display not working ?

2020-02-22 Thread Mike Dewhirst
Maybe the choices should beSTATUS = [    ('draft', _('Draft')),    ...]I think 
the migration system might detect a change in the model every time it is run 
because the get_text_lazy() function can return a non-static result. Not sure 
about that.I haven't used _() myself but I have used methods to fill up choices 
lists with just that outcome. I had to finalize the list prior to running 
migrate.Not much help I knowGood luckMike
 Original message From: Yves de Champlain  
Date: 23/2/20  15:47  (GMT+10:00) To: Django users 
 Subject: get_FOO_display not working ? HiI'm 
using StatusModel from models_utils :class MetaData(TimeStampedModel, 
StatusModel, SoftDeletableModel):    STATUS = Choices(('draft', _('Draft')),    
                 ('submitted', _('Submitted')),                     
('underreview', _('Underreview')),                      )Forms using STATUS 
work as expected, but when I load an object from the DB, I can't access the 
human readable data in my templates.a.status => drafta.get_status_display => 
draftinstead ofa.status => drafta.get_status_display => DraftThanks for any hep 
on this !



-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d7a06913-39a8-4e55-9799-ebc46cb5cde4%40googlegroups.com.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e522a9f.1c69fb81.cae91.b7f5SMTPIN_ADDED_MISSING%40gmr-mx.google.com.


Re: get_FOO_display not working ?

2020-02-22 Thread Nde Nguti
CHOICES =(('draft', 'Draft'), )

On Sun, Feb 23, 2020, 05:48 Yves de Champlain  wrote:

> Hi
>
> I'm using StatusModel from models_utils :
>
> class MetaData(TimeStampedModel, StatusModel, SoftDeletableModel):
> STATUS = Choices(('draft', _('Draft')),
>  ('submitted', _('Submitted')),
>  ('underreview', _('Underreview')),
>   )
>
> Forms using STATUS work as expected, but when I load an object from the
> DB, I can't access the human readable data in my templates.
>
> a.status => draft
> a.get_status_display => draft
>
> instead of
>
> a.status => draft
> a.get_status_display => Draft
>
> Thanks for any hep on this !
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d7a06913-39a8-4e55-9799-ebc46cb5cde4%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALfkE84BbTc47u0TGL_PWYNXpoXjs0rsZUG4rjSBNySd8SLGyw%40mail.gmail.com.


Re: get_FOO_display not working ?

2020-02-22 Thread Nde Nguti
Try
('draft', 'Draft') not ('draft', ('Draft'))




On Sun, Feb 23, 2020, 05:48 Yves de Champlain  wrote:

> Hi
>
> I'm using StatusModel from models_utils :
>
> class MetaData(TimeStampedModel, StatusModel, SoftDeletableModel):
> STATUS = Choices(('draft', _('Draft')),
>  ('submitted', _('Submitted')),
>  ('underreview', _('Underreview')),
>   )
>
> Forms using STATUS work as expected, but when I load an object from the
> DB, I can't access the human readable data in my templates.
>
> a.status => draft
> a.get_status_display => draft
>
> instead of
>
> a.status => draft
> a.get_status_display => Draft
>
> Thanks for any hep on this !
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d7a06913-39a8-4e55-9799-ebc46cb5cde4%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALfkE84yXRmXK-34WLxHq_yVMWMf8ngghORVuX4GXdzeXk6f8g%40mail.gmail.com.


get_FOO_display not working ?

2020-02-22 Thread Yves de Champlain
Hi

I'm using StatusModel from models_utils :

class MetaData(TimeStampedModel, StatusModel, SoftDeletableModel):
STATUS = Choices(('draft', _('Draft')),
 ('submitted', _('Submitted')),
 ('underreview', _('Underreview')),
  )

Forms using STATUS work as expected, but when I load an object from the DB, 
I can't access the human readable data in my templates.

a.status => draft
a.get_status_display => draft

instead of

a.status => draft
a.get_status_display => Draft

Thanks for any hep on this !

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d7a06913-39a8-4e55-9799-ebc46cb5cde4%40googlegroups.com.


Re: get_FOO_display() for generic/variable choice fields

2012-01-27 Thread Michael Elkins

On Tue, Jan 24, 2012 at 03:51:27AM -0800, katstevens wrote:

Obviously the 'val = obj.get_field_display()' line doesn't work!

Is there a generic way of doing this (something like
obj.get_display(fieldname) ?) or am I going to have to hard code
separate checks for get_country_display() and
get_dialing_code_display()?


I think you can do what you want like this:

obj = queryset[my_item]

for field in obj._meta.fields:
if field.choices:
val = obj._get_FIELD_display(field)
else:
val = getattr(obj, field.name)
row.append(val)

--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: get_FOO_display() for generic/variable choice fields

2012-01-25 Thread katstevens
My Python-expert partner suggested a clever workaround as follows:

As I'm already running through the model._meta.fields beforehand to
create header row for my .csv file, I can build a dictionary of the
choices to refer to later.

choices_lookup_dict = {}
header_row = []

for field in model._meta.fields:
  # create header row for csv file
  header_row.append(field.name)
  # Add lookup dictionary of choices to dictionary of fields
  #  i.e. creating a dictionary of dictionaries for each choice field
  if field.choices:
choices_lookup_dict[field.name] = dict(field.choices)

This could be quite expensive for large choice tuples such as country
lists, but at least we're only calling it once.

So now in my main loop I can use the following code to lookup my
verbose choice value:


for field in model._meta.fields:
   val = getattr(obj, field.name)
   if field.choices:
 val = choices_lookup_dict[field.name][val]
   row.append(val)


We assume that get_FOO_display() must be doing something like this
anyway!

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: get_FOO_display() for generic/variable choice fields

2012-01-24 Thread Bill Freeman
Maybe try:

val = getattr(obj, 'get_%s_display' % field.name)()


On 1/24/12, katstevens  wrote:
> I have a model ContactDetail with two choice fields,
> ContactDetail.dialing_code and ContactDetail.country. These use the
> standard tuples ('AU', 'Australia') and so on.
>
> I know I can use get_country_display() and get_dialing_code_display()
> to show the longer values, but is there a more generic version where
> the field name is replaced with a variable?
>
> For example, I want to create a customised .csv file from the model
> data. I can loop through the fields from my model and get the shorter
> attribute values without any problems. However I'd like to do
> something like this:
>
>   obj = queryset[my_item] # an instance of ContactDetail()
>   model = queryset.model # ContactDetail() itself
>
>   for field in model._meta.fields:
>   val = getattr(obj, field.name)  # gets the shorter version
>   if field.choices:# if field is ChoiceField, 
> convert data
> to display mode
>   val = obj.get_field_display()
>   row.append(val)
>
> Obviously the 'val = obj.get_field_display()' line doesn't work!
>
> Is there a generic way of doing this (something like
> obj.get_display(fieldname) ?) or am I going to have to hard code
> separate checks for get_country_display() and
> get_dialing_code_display()?
>
> Ideally I would like to use this particular function for other models
> and keep the fields as generic as possible.
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



get_FOO_display() for generic/variable choice fields

2012-01-24 Thread katstevens
I have a model ContactDetail with two choice fields,
ContactDetail.dialing_code and ContactDetail.country. These use the
standard tuples ('AU', 'Australia') and so on.

I know I can use get_country_display() and get_dialing_code_display()
to show the longer values, but is there a more generic version where
the field name is replaced with a variable?

For example, I want to create a customised .csv file from the model
data. I can loop through the fields from my model and get the shorter
attribute values without any problems. However I'd like to do
something like this:

obj = queryset[my_item] # an instance of ContactDetail()
model = queryset.model # ContactDetail() itself

for field in model._meta.fields:
val = getattr(obj, field.name)  # gets the shorter version
if field.choices:# if field is ChoiceField, 
convert data
to display mode
val = obj.get_field_display()
row.append(val)

Obviously the 'val = obj.get_field_display()' line doesn't work!

Is there a generic way of doing this (something like
obj.get_display(fieldname) ?) or am I going to have to hard code
separate checks for get_country_display() and
get_dialing_code_display()?

Ideally I would like to use this particular function for other models
and keep the fields as generic as possible.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: get_FOO_display

2011-12-13 Thread Mike Dewhirst
Absolutely. I went back and found where I had made it work previously and that 
is exactly what I did. I just had a (hopefully) temporary blur. 

Thanks

Mike

On 13/12/2011, at 8:47 PM, Ilian Iliev  wrote:

> Or you can change your field to IntegerField instead of CharField if you are 
> planning to have only Integer
> values for the choices.
> 
> 
> -- 
> eng. Ilian Iliev
> Web Software Developer
> 
> Mobile: +359 88 66 08 400
> Website: http://ilian.i-n-i.org
> 
> 
> On Tue, Dec 13, 2011 at 9:53 AM, Mike Dewhirst  wrote:
> On 13/12/2011 5:21pm, kenneth gonsalves wrote:
> On Tue, 2011-12-13 at 17:16 +1100, Mike Dewhirst wrote:
> THINGS = ( (0, 'Thing Zero'),
> (1, 'Thing One'), )
> 
> what happens when you do:
> 
> THINGS = ( ('0', 'Thing Zero'),
> ('1', 'Thing One'), )
> 
> 
> By golly it worked! Must have missed that in the docs.
> 
> Thanks Kenneth
> 
> Mike
> 
> 
> -- 
> 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 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 
> -- 
> 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 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: get_FOO_display

2011-12-13 Thread Ilian Iliev
Or you can change your field to IntegerField instead of CharField if you
are planning to have only Integer
values for the choices.


-- 
eng. Ilian Iliev
Web Software Developer

Mobile: +359 88 66 08 400
Website: http://ilian.i-n-i.org


On Tue, Dec 13, 2011 at 9:53 AM, Mike Dewhirst wrote:

> On 13/12/2011 5:21pm, kenneth gonsalves wrote:
>
>> On Tue, 2011-12-13 at 17:16 +1100, Mike Dewhirst wrote:
>>
>>> THINGS = ( (0, 'Thing Zero'),
>>> (1, 'Thing One'), )
>>>
>>
>> what happens when you do:
>>
>> THINGS = ( ('0', 'Thing Zero'),
>> ('1', 'Thing One'), )
>>
>
>
> By golly it worked! Must have missed that in the docs.
>
> Thanks Kenneth
>
> Mike
>
>
> --
> 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 django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: get_FOO_display

2011-12-12 Thread Mike Dewhirst

On 13/12/2011 5:21pm, kenneth gonsalves wrote:

On Tue, 2011-12-13 at 17:16 +1100, Mike Dewhirst wrote:

THINGS = ( (0, 'Thing Zero'),
 (1, 'Thing One'), )


what happens when you do:

THINGS = ( ('0', 'Thing Zero'),
 ('1', 'Thing One'), )



By golly it worked! Must have missed that in the docs.

Thanks Kenneth

Mike

--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: get_FOO_display

2011-12-12 Thread kenneth gonsalves
On Tue, 2011-12-13 at 17:16 +1100, Mike Dewhirst wrote:
> THINGS = ( (0, 'Thing Zero'),
> (1, 'Thing One'), ) 

what happens when you do:

THINGS = ( ('0', 'Thing Zero'),
('1', 'Thing One'), ) 
-- 
regards
Kenneth Gonsalves

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



get_FOO_display

2011-12-12 Thread Mike Dewhirst

I'm getting a puzzling error trying to follow the dev docs here ...

https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.get_FOO_display

I syncdb'd a simple test model to eliminate everything except the 
essentials with ...


class SimpleTest(models.Model):

THINGS = ( (0, 'Thing Zero'),
   (1, 'Thing One'), )

name = models.CharField(max_length=64, choices=THINGS)

def __unicode__(self):
return u'%s' % self.get_name_display()

... But in django.admin trying to save a SimpleTest after choosing one 
of the available things the error is ...


Please correct the error below.

Value u'1' is not a valid choice.


This is Django 1.4 pre-alpha SVN-17200 running on Windows XP SP3 and 
Python 2.7


I'm 99% sure I have had get_FOO_display() working in the past. Can 
anybody please show me the error of my ways?


Thanks

Mike

--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



[1.3] get_FOO_display() and prepopulated_fields?

2011-10-18 Thread Micky Hulse
Hello,

Are there any tricks to getting the display value of a choice field to
work with prepopulated_fields slug creation in the admin?



class Team(Base):

MALE = 1
FEMALE = 2
GENDER_CHOICES = (
(MALE, u'Men'),
(FEMALE, u'Women'),
)

slug = models.SlugField(_(u'slug'), max_length=100, unique=True,
db_index=True)
gender = models.IntegerField(_(u'gender'), choices=GENDER_CHOICES)

class TeamAdmin(admin.ModelAdmin):

prepopulated_fields = {
'slug': (
'title',
'gender',
)
}



The above (kinda) works, but it returns:

oregon-1
oregon-2

I would prefer if it returned:

oregon-men
oregon-women

Is there anyway for me to use get_gender_display in the admin's
prepopulated_fields?

Thanks!
Micky

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Utilization of get_FOO_display()

2010-02-08 Thread Karen Tracey
On Mon, Feb 8, 2010 at 8:51 AM, mf  wrote:

> I want to show the human-readable name for the type selected but I
> keep getting the stored value.
>
> TYPE_CHOICES = (
>('0', 'Basic'),
>('1', 'Full'),
>('2', 'Intermediate'),
> )
>
> class ServiceType(models.Model):
>type = models.IntegerField(max_length=1, choices=TYPE_CHOICES)
>amount = models.DecimalField(max_digits=10, decimal_places=2)
>
>def __unicode__(self):
>return '%s' % (self.get_type_display())
>

The model's type field is an IntegerField yet the actual values in the
choice tuples are strings. This works OK for storing but fails to match when
the real value retrieved from the DB is an integer, since '1' == 1 evaluates
to False, for example.  Thus get_type_display() doesn't find any choice that
matches the retrieved value and falls back to returning the actual value.
Switch the '0', '1', '2' in TYPE_CHOICES to 0,1,2, and it will work.

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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Utilization of get_FOO_display()

2010-02-08 Thread mf
I want to show the human-readable name for the type selected but I
keep getting the stored value.

TYPE_CHOICES = (
('0', 'Basic'),
('1', 'Full'),
('2', 'Intermediate'),
)

class ServiceType(models.Model):
type = models.IntegerField(max_length=1, choices=TYPE_CHOICES)
amount = models.DecimalField(max_digits=10, decimal_places=2)

def __unicode__(self):
return '%s' % (self.get_type_display())

http://pastebin.com/m7ff5a1de

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



Re: get_FOO_display

2009-02-06 Thread Alex Koshelev
get_FOO_display is an instance method not field. So try this:

{{ object.get_invoice_type_display }}



On Fri, Feb 6, 2009 at 6:09 PM, Alfonso <allanhender...@gmail.com> wrote:

>
> I've got a field called 'invoice_type' which is a ChoiceField.
>
> In my template I'm trying to pull out the 'humanized' invoice type by
> using {{ object.invoice_type.get_invoice_type_display }} but django's
> not happy.  I'm guessing it's because of the invoice[underscore]type
> syntax I used?
>
> Any workarounds?
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



get_FOO_display

2009-02-06 Thread Alfonso

I've got a field called 'invoice_type' which is a ChoiceField.

In my template I'm trying to pull out the 'humanized' invoice type by
using {{ object.invoice_type.get_invoice_type_display }} but django's
not happy.  I'm guessing it's because of the invoice[underscore]type
syntax I used?

Any workarounds?

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_FOO_display() and Update Messages

2008-05-03 Thread Karen Tracey
On Sat, May 3, 2008 at 2:15 AM, Greg Taylor <[EMAIL PROTECTED]> wrote:

>
> I was wondering if there's any reason why get_FOO_display() calls
> aren't being evaluated when updating/adding new objects via the admin
> interface. What I mean by this is:
>
> The workout "1" was changed successfully.
>
> Instead of:
>
> The workout "Running" was changed successfully.
>
> The field in question is an IntegerField with a choices tuple defined
> that looks like:
>
> WORKOUT_TYPE_CHOICES = (
>  (0, "Biking"),
>  (1, "Running"),
> )
>
> The class' __str__ method looks like this:
> return self.get_activity_type_display()
>
> Any ideas?
>

Sound like this problem:

http://code.djangoproject.com/ticket/6853

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: get_FOO_display() and Update Messages

2008-05-03 Thread dimrub

Yay another fitness app based on django!

http://code.google.com/p/fiteat/

On May 3, 9:15 am, Greg Taylor <[EMAIL PROTECTED]> wrote:
> I was wondering if there's any reason why get_FOO_display() calls
> aren't being evaluated when updating/adding new objects via the admin
> interface. What I mean by this is:
>
> The workout "1" was changed successfully.
>
> Instead of:
>
> The workout "Running" was changed successfully.
>
> The field in question is an IntegerField with a choices tuple defined
> that looks like:
>
> WORKOUT_TYPE_CHOICES = (
>   (0, "Biking"),
>   (1, "Running"),
> )
>
> The class' __str__ method looks like this:
> return self.get_activity_type_display()
>
> Any ideas?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



get_FOO_display() and Update Messages

2008-05-03 Thread Greg Taylor

I was wondering if there's any reason why get_FOO_display() calls
aren't being evaluated when updating/adding new objects via the admin
interface. What I mean by this is:

The workout "1" was changed successfully.

Instead of:

The workout "Running" was changed successfully.

The field in question is an IntegerField with a choices tuple defined
that looks like:

WORKOUT_TYPE_CHOICES = (
  (0, "Biking"),
  (1, "Running"),
)

The class' __str__ method looks like this:
return self.get_activity_type_display()

Any ideas?
--~--~-~--~~~---~--~~
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: get_foo_display doesn't work with integers?

2007-12-29 Thread Florian Apolloner

I found the issue (or non issue, whatever you like ;))

get_test_char_display() calls the field's choices with a string (of
course it is a CharField), which results in the following call
(stripped down talen from django/db/models/base.py:
dict(choices).get(value,value)
Now accesing it with a string as value would raise a KeyError so the
value saved in the CharField is returned, which is a string containing
an int.

The remaining question now is whether this should get documented
somehow (eg match the type of the field...) or not. Of course it
doesn't make sense to use integers and then store them in the db, but
this question popped up a few times in irc...


On Dec 29, 10:32 pm, Florian Apolloner <[EMAIL PROTECTED]> wrote:
> > Error is in the way you use it. Please write full model and usage
> > example.
>
> As you wish :)
>
> blubb/models.py:
>
> from django.db import models
>
> # Create your models here.
> MY_CHOICES = (
> (1, '11'),
> (2, '12')
> )
> class TestModel(models.Model):
> test_blubb = models.IntegerField(choices=MY_CHOICES)
> test_char = models.CharField(choices=MY_CHOICES, max_length=100)
>
> Testcode
> ./manage.py shell
> Python 2.4.4 (#2, Aug 16 2007, 02:03:40)
> [GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)>>> from blubb.models import *
> >>> a = TestModel.objects.get(pk=1)
> >>> a.get_test_blubb_display()
> u'11'
> >>> a.get_test_char_display()
>
> u'2'
>
> Where the last one should be u'12' instead of u'2'. The problem seems
> to be with CharField. If I use str for all the choices it does work...
--~--~-~--~~~---~--~~
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: get_foo_display doesn't work with integers?

2007-12-29 Thread Florian Apolloner

> Error is in the way you use it. Please write full model and usage
> example.

As you wish :)

blubb/models.py:


from django.db import models

# Create your models here.
MY_CHOICES = (
(1, '11'),
(2, '12')
)
class TestModel(models.Model):
test_blubb = models.IntegerField(choices=MY_CHOICES)
test_char = models.CharField(choices=MY_CHOICES, max_length=100)

Testcode
./manage.py shell
Python 2.4.4 (#2, Aug 16 2007, 02:03:40)
[GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from blubb.models import *
>>> a = TestModel.objects.get(pk=1)
>>> a.get_test_blubb_display()
u'11'
>>> a.get_test_char_display()
u'2'


Where the last one should be u'12' instead of u'2'. The problem seems
to be with CharField. If I use str for all the choices it does work...
--~--~-~--~~~---~--~~
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: get_foo_display doesn't work with integers?

2007-12-29 Thread Alex Koshelev

Error is in the way you use it. Please write full model and usage
example.

On 29 дек, 23:54, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> apollo13 pointed this out on the IRC channel:
> If your choices use an integers, get_foo_display returns the integer
> and not the "human readable" option.
>
> For example, reworking this from the docs:
> YEAR_IN_SCHOOL_CHOICES = (
> (1, 'Freshman'),
> (2, 'Sophomore'),
> (3, 'Junior'),
> (4, 'Senior'),
> (5, 'Graduate'),
> )
>
> get_foo_display would show 1 instead of "Freshman". The select widget
> works right either way.
>
> Is this expected behavior? Or should ints work?
>
> If this is expected behavior, perhaps we need a note in the docs to
> that effect (I'd be glad to open the ticket).
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



get_foo_display doesn't work with integers?

2007-12-29 Thread [EMAIL PROTECTED]

apollo13 pointed this out on the IRC channel:
If your choices use an integers, get_foo_display returns the integer
and not the "human readable" option.

For example, reworking this from the docs:
YEAR_IN_SCHOOL_CHOICES = (
(1, 'Freshman'),
(2, 'Sophomore'),
(3, 'Junior'),
(4, 'Senior'),
(5, 'Graduate'),
)

get_foo_display would show 1 instead of "Freshman". The select widget
works right either way.

Is this expected behavior? Or should ints work?

If this is expected behavior, perhaps we need a note in the docs to
that effect (I'd be glad to open the ticket).
--~--~-~--~~~---~--~~
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: Using get_FOO_display() in admin classes

2007-04-23 Thread oggie rob

The last I heard, choices only worked for CharFields. Probably it is
trying to compare 600.0 with '600.0' and failing, so it resorts to the
unmatched "-", or failing to save the value properly in the first
place. Docs don't clarify, though - it might have changed recently.
If so, your best bet (if possible) is to use a char field representing
that value & convert it later on. What I have done in those cases is
to use a dict to hold all the values & generate tuples from that dict.

 -rob

On Apr 23, 5:16 am, "Hancock, David (DHANCOCK)" <[EMAIL PROTECTED]>
wrote:
> Django-0.96. I've discovered the get_FOO_display() function that I get for
> free when I use a "choices=CHOICES" in a model, and I understand how to use
> it in a template or in the API. But the problem I'm having is that when I
> save something with a choices attribute, editing that object subsequently
> shows the item as "-" (as if it's never been set before).
>
> For example:
>
> ALLOWED=((600.0, 'Area 1'), (1200.0, 'Area 2')
> class something(models.Model):
> ...
> area_charge = models.FloatField(max_digits=7, decimal_places=2,
> choices=ALLOWED
> ...
>
> The select box populates with Area 1 and Area 2, and the float gets
> populated in the database correctly as 600 or 1200 based on the selection.
> But after saving, say, 600.0 as the area_charge, editing that item again
> yields the same select box as initial entry, but the Area 1 entry is no
> longer selected; the row of hyphens is showing. Saving in this condition
> elicits an error message because the entry is required.
>
> I'd like to see the 600.0 stored in the database cause Area 1 to be selected
> when the item is opened for editing. This seems exactly like what
> get_area_charge_display() should do, but I can't figure out where it goes in
> the model/admin classes.
>
> Thanks for any light you can shed on this.
>
> Cheers!
> --
> David Hancock | [EMAIL PROTECTED]


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



Using get_FOO_display() in admin classes

2007-04-23 Thread Hancock, David (DHANCOCK)
Django-0.96. I've discovered the get_FOO_display() function that I get for
free when I use a "choices=CHOICES" in a model, and I understand how to use
it in a template or in the API. But the problem I'm having is that when I
save something with a choices attribute, editing that object subsequently
shows the item as "-" (as if it's never been set before).

For example:

ALLOWED=((600.0, 'Area 1'), (1200.0, 'Area 2')
class something(models.Model):
...
area_charge = models.FloatField(max_digits=7, decimal_places=2,
choices=ALLOWED
...

The select box populates with Area 1 and Area 2, and the float gets
populated in the database correctly as 600 or 1200 based on the selection.
But after saving, say, 600.0 as the area_charge, editing that item again
yields the same select box as initial entry, but the Area 1 entry is no
longer selected; the row of hyphens is showing. Saving in this condition
elicits an error message because the entry is required.

I'd like to see the 600.0 stored in the database cause Area 1 to be selected
when the item is opened for editing. This seems exactly like what
get_area_charge_display() should do, but I can't figure out where it goes in
the model/admin classes.

Thanks for any light you can shed on this.

Cheers!
-- 
David Hancock | [EMAIL PROTECTED]


--~--~-~--~~~---~--~~
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: Does django provide a parse_FOO_display? ie. get_FOO_display reverted.

2007-03-27 Thread Malcolm Tredinnick

On Tue, 2007-03-27 at 19:11 -0700, Alex Dong wrote:
> Hi Folks,
> 
> I'm wondering are there any "parse_FOO_display" method for the django
> models?
> 
> For example:   {{{
> class Transaction(models.Model):
> STATUS = (
> (1, 'Canceled_Reversal'),
> (2, 'Completed'),
> (3, 'Pending'),
> (4, 'Refunded'),
> (5, 'Reversed'),
> (6, 'Processed'))
> status  = models.PositiveSmallIntegerField(choices=STATUS)
> }}}
> 
> I know that I could call "tx.get_status_display()" to get descriptive
> name for the status, say "Completed". But how can I get `2` when given
> the descriptive name `Completed`?

There's no standard method to do that. It doesn't seem to be a very
common requirement. You could write one yourself if you wanted to:

def get_less_readable_version(self, choice):
choices = self._meta.get_field('status').choices
for val, name in choices:
if name == choice:
return val

Obviously a few variations on this theme are possible, such as putting
the choices in a dictionary once and then doing a lookup. The only
slightly tricky thing here is the _meta.get_field(...).choices call to
get the choices list for a particular field.

Regards,
Malcolm



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



Does django provide a parse_FOO_display? ie. get_FOO_display reverted.

2007-03-27 Thread Alex Dong

Hi Folks,

I'm wondering are there any "parse_FOO_display" method for the django
models?

For example:   {{{
class Transaction(models.Model):
STATUS = (
(1, 'Canceled_Reversal'),
(2, 'Completed'),
(3, 'Pending'),
(4, 'Refunded'),
(5, 'Reversed'),
(6, 'Processed'))
status  = models.PositiveSmallIntegerField(choices=STATUS)
}}}

I know that I could call "tx.get_status_display()" to get descriptive
name for the status, say "Completed". But how can I get `2` when given
the descriptive name `Completed`?

Alex


--~--~-~--~~~---~--~~
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: get_FOO_display and grouped data

2006-12-04 Thread Ross Burton

Jacob Kaplan-Moss wrote:
> Try::
>
> {% regroup feature.task_set.all|dictsortreversed:"priority" by
> get_priority_display as grouped %}
>
> That is, the "by" argument to {% regroup %} doesn't just have to be a field
> name; it can be anything that a variable could resolve.

Excellent, thanks.

Ross


--~--~-~--~~~---~--~~
 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: get_FOO_display and grouped data

2006-12-04 Thread Jacob Kaplan-Moss

On 12/4/06 4:34 PM, Ross Burton wrote:
> In my view, I'm grouping the data on the priority:
> 
> {% regroup feature.task_set.all|dictsortreversed:"priority" by priority
> as grouped %}
> {% for group in grouped %}
>   {{ group.grouper }}
> 
> However, when I do this, group.grouper expands to "0" or "2", not "Low"
> or High".  How can I get the display name for this field?

Try::

{% regroup feature.task_set.all|dictsortreversed:"priority" by 
get_priority_display as grouped %}

That is, the "by" argument to {% regroup %} doesn't just have to be a field 
name; it can be anything that a variable could resolve.

Jacob

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



get_FOO_display and grouped data

2006-12-04 Thread Ross Burton

Hi,

I have a model with an integer field that uses choices for display
names:

class Task(models.Model):
PRIORITY_CHOICES = (
('0', 'Low'),
('1', 'Normal'),
('2', 'High')
)
priority = models.IntegerField(choices=PRIORITY_CHOICES)

In my view, I'm grouping the data on the priority:

{% regroup feature.task_set.all|dictsortreversed:"priority" by priority
as grouped %}
{% for group in grouped %}
  {{ group.grouper }}

However, when I do this, group.grouper expands to "0" or "2", not "Low"
or High".  How can I get the display name for this field?

Thanks,
Ross


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



get_FOO_display for a grouper

2006-11-08 Thread sorrison

I have a class with a "site" field that uses choices
I want to display the human readable name for it when being used as a
grouper

i thought something like
site.get_grouper_display or get_site.grouper_display

but that doesn't work

here is the template code

{% regroup object_list|dictsort:"group" by group as sites %}

{% for site in sites %}
{{ site.grouper }}

{% for buddy in site.list %}
{{ buddy.alias
}}
{% endfor %}

{% endfor %}


is there a way to do it?

Thanks,

Sam


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