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

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

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 t

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', _('Sub

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')), > (

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_dia

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.

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_cou

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

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 1

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! Mus

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

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

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

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

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 strin

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_C

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.

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. Ro

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" o