Re: Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-24 Thread Vladimir Sidorenko
Hi George, as far as I remember, ChoiceField has a line like: self.choices = list(choices) in __init__ method. Until this is changed, there is no difference in passing a callable, a list, or a generator. So what do you suggest: To simply allow passing a callable, or to allow truly dynamic c

Re: Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-24 Thread George Karpenkov
oh wait, you're right. (though choices=my_func seems to be neater then choices=(c for c in my_func()) (for some reason i thought that choices=(c for c in my_func()) will evaluate the my_func before we'll iterate through choices, but it won't) On Mar 24, 5:48 pm, Ivan Sagalaev wrote: > George Kar

Re: Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-24 Thread Luca Sbardella
Hi there, I've used a different approach to solve the problem. If of interest, here is the snippet http://gist.github.com/232372 for solving the the problem of a run-time ChoiceField. The choices argument is a generator (or the usual list of tuples). On 24 March 2010 06:48, Ivan Sagalaev wrote:

Re: Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-23 Thread Ivan Sagalaev
George Karpenkov wrote: Given your experience, the chances are that you're right, however, I don't see any way how we can pass a generator which will not be called until the form class is instantiated. Why should a call matter? The body of the generator is not executed until first iteration at

Re: Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-23 Thread George Karpenkov
Hi Ivan, Given your experience, the chances are that you're right, however, I don't see any way how we can pass a generator which will not be called until the form class is instantiated. We can't pass a generator function to choices (list() call will fail); we can pass the generator expression bu

Re: Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-23 Thread Ivan Sagalaev
George Karpenkov wrote: http://code.djangoproject.com/ticket/13181 I'm -1 on complicating it this way. The ability to pass a callable for choices is covered by passing a generator. Am I missing something? -- You received this message because you are subscribed to the Google Groups "Django d

Re: Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-22 Thread George Karpenkov
http://code.djangoproject.com/ticket/13181 On Mar 23, 4:42 pm, Jared Forsyth wrote: > I say go for it, and post again with a patch and issue number (once you've > created them). Your idea seems sound. > > Jared > > On Mon, Mar 22, 2010 at 11:30 PM, George Karpenkov > wrote: > > > > > Hi, > > > Th

Re: Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-22 Thread Jared Forsyth
I say go for it, and post again with a patch and issue number (once you've created them). Your idea seems sound. Jared On Mon, Mar 22, 2010 at 11:30 PM, George Karpenkov wrote: > Hi, > > The subject pretty much describes all of it. If 'initial' can be a > callable, why 'choices' can't? Writing c

Proposal - ChoiceField.choices need to accept callable, not only list or tuple

2010-03-22 Thread George Karpenkov
Hi, The subject pretty much describes all of it. If 'initial' can be a callable, why 'choices' can't? Writing custom function is way more convenient then altering __init__ method of the model. I'm happy to write up a patch if it would be likely to be accepted -- You received this message becaus