Django model's field dynamic choices

2018-05-14 Thread Marcin
I'm using Django 1.11. I cannot set dynamic choices for model's field because: - choices must be iterable, not function, - choices iterable is always coverted to list, - iterable is evaluated oat the module import stage. The whole thing is about iterable evaluation time

Re: How do I get dynamic choices to a select widget at render time?

2018-02-22 Thread Mike Dewhirst
On 20/02/2018 11:51 PM, Andy wrote: use django-select2 Had a look at the docs and django-select2 doesn't address this use case. However, I can see I will need it for ORM related selections in the near term. Thanks Andy. Am Dienstag, 20. Februar 2018 01:17:26 UTC+1 schrieb Mike Dewhirst:

Re: How do I get dynamic choices to a select widget at render time?

2018-02-20 Thread Andy
use django-select2 Am Dienstag, 20. Februar 2018 01:17:26 UTC+1 schrieb Mike Dewhirst: > > Here is an example of get_choices() output ... it comes from a method on > the Question model. > > [('A', 'A - Once?'), ('B', 'B - Twice?'), ('C', 'C - Four times?'), > ('D', 'D - Twelve times?'), ('E',

Re: How do I get dynamic choices to a select widget at render time?

2018-02-20 Thread Mike Dewhirst
On 20/02/2018 11:16 AM, Mike Dewhirst wrote: Here is an example of get_choices() output ... it comes from a method on the Question model.  [('A', 'A - Once?'), ('B', 'B - Twice?'), ('C', 'C - Four times?'), ('D', 'D - Twelve times?'), ('E', 'E - Continously as changes are made?')] It is ava

How do I get dynamic choices to a select widget at render time?

2018-02-19 Thread Mike Dewhirst
Here is an example of get_choices() output ... it comes from a method on the Question model.  [('A', 'A - Once?'), ('B', 'B - Twice?'), ('C', 'C - Four times?'), ('D', 'D - Twelve times?'), ('E', 'E - Continously as changes are made?')] It is available before the the answer form is instantiat

Re: dynamic choices based on another field input.

2017-10-22 Thread Derek
See: http://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#filtering-results-based-on-the-value-of-other-fields-in-the-form On Friday, 20 October 2017 13:04:41 UTC+2, rajeev yadla wrote: > > hi have a form which have two fields. one field has a foreignkey from > model A(in ima

dynamic choices based on another field input.

2017-10-20 Thread rajeev yadla
hi have a form which have two fields. one field has a foreignkey from model A(in image) base field. and another field is a drop down box where the choices should be dynamic based on first field selection. the choices should all the values of field Os from second model B associated with the Ba

Re: A small bug for dynamic choices

2013-02-14 Thread vijay shanker
code is getting executed when Django validates it's models. Hence, Cartprobably has not been validated yet and it's model class is None. On Monday, February 11, 2013 4:29:44 PM UTC+5:30, vijay shanker wrote: > > hi > i wrote a function for producing tuples of all model names, which is this: >

Re: A small bug for dynamic choices

2013-02-11 Thread vijay shanker
I found out that ('shoppingcart.models.Cart', 'Cart') is lost coz it doesnot finds any model_class (i.e model_class is None and is thus filtered out ) when i am running the code but it does finds the model_class from python shell. something which is not very obvious is happening. On Monday, F

A small bug for dynamic choices

2013-02-11 Thread vijay shanker
hi i wrote a function for producing tuples of all model names, which is this: from django.contrib.contenttypes.models import ContentType from django.db.models.loading import get_model def get_all_models(): return tuple([(each.__module__+'.'+each.__name__,each.__name__) for each in [each.mode

Dynamic choices on inlines

2012-08-27 Thread Mariano DAngelo
Hi, I'm new in django and I'm searching how to the following... I've the following models class Fighter(Person): pass class Fight_Event(models.Model): pass # INLINE MODEL class Fight(models.Model): event = models.ForeignKey(Fight_Event) fighter1 = models.ForeignKey(Fighter,rela

Re: formeset choicefield dynamic choices

2012-08-08 Thread Melvyn Sopacua
On 8-8-2012 15:32, BiG-Up wrote: > I'm working on a formset with dynamic forms. I've overloaded my form > to be able to add new values in the select field but i cannot > overload the formset constructor. Django raise exception : > "__init__() takes exactly 1 argument (2 given)" formset.add_fields

formeset choicefield dynamic choices

2012-08-08 Thread BiG-Up
Hi, I'm working on a formset with dynamic forms. I've overloaded my form to be able to add new values in the select field but i cannot overload the formset constructor. Django raise exception : "__init__() takes exactly 1 argument (2 given)" - How can i change the way the formset_factory build

Form wizard and dynamic choices

2011-11-26 Thread brian mckinney
I've been trying to implement a relatively simple django app, in which I need to have a multistep form and a dynamically generated choice field. I'm using Django 1.3 and the Form Wizard. In step one of the form, I ask for a URL from the user, which I'd like to use to dynamically generate the list

Re: Dynamic Choices for ChoiceField

2009-08-01 Thread mviamari
On Jul 31, 7:37 pm, Malcolm Tredinnick wrote: > On Fri, 2009-07-31 at 16:31 -0700,mviamariwrote: > > Hello, > > > I'm trying to make a form for data entry into my database that uses > > ChoiceFields for foreign keys.  Obviously, the ideal choice would be > > ModelChoiceField, however I'm not usin

Re: Dynamic Choices for ChoiceField

2009-07-31 Thread Malcolm Tredinnick
On Fri, 2009-07-31 at 16:31 -0700, mviamari wrote: > Hello, > > I'm trying to make a form for data entry into my database that uses > ChoiceFields for foreign keys. Obviously, the ideal choice would be > ModelChoiceField, however I'm not using the django ORM, so I've > assumed that's not going t

Dynamic Choices for ChoiceField

2009-07-31 Thread mviamari
Hello, I'm trying to make a form for data entry into my database that uses ChoiceFields for foreign keys. Obviously, the ideal choice would be ModelChoiceField, however I'm not using the django ORM, so I've assumed that's not going to work (I'm using Elixir/SQLAlchemy). I originally set the cho

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Sam Chuparkoff
On Sun, 2009-05-17 at 20:01 -0700, Bobby Roberts wrote: > yeah i'm still lost... You don't need to change your form, just use form.cleaned_data in your view. Same example, a few more lines: >>> # our form ... >>> from django import forms >>> from django.contrib.auth.models import User >>> >>>

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
> You should be looking in cleaned_data, see: > > http://docs.djangoproject.com/en/1.0/topics/forms/#processing-the-dat... > > For a ModelMultipleChoiceField, cleaned_data will be a list of model > instances. You shouldn't even have to think about the pk s. > > sdc yeah i'm still lost... this is

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Sam Chuparkoff
On Sun, 2009-05-17 at 18:43 -0700, Bobby Roberts wrote: > in my view i have this: > > > if request.method=='POST': > form=FrmIdMessage(request.POST) > if form.is_valid(): #process valid form here > assert False, request.POST.get('posted_to','') > [snip] You sho

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
On May 17, 4:23 pm, Bobby Roberts wrote: > > ...     users = forms.ModelMultipleChoiceField( > > ...         queryset=User.objects, > > ...         widget=forms.CheckboxSelectMultiple, > > ...         required=True) > > ...>>> User(username='sdc').save() > > >>> User(username='bobby').save() > o

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
On May 17, 4:23 pm, Bobby Roberts wrote: > > ...     users = forms.ModelMultipleChoiceField( > > ...         queryset=User.objects, > > ...         widget=forms.CheckboxSelectMultiple, > > ...         required=True) > > ...>>> User(username='sdc').save() > > >>> User(username='bobby').save() > o

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
On May 17, 4:23 pm, Bobby Roberts wrote: > > ...     users = forms.ModelMultipleChoiceField( > > ...         queryset=User.objects, > > ...         widget=forms.CheckboxSelectMultiple, > > ...         required=True) > > ...>>> User(username='sdc').save() > > >>> User(username='bobby').save() > o

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Sam Chuparkoff
On Sun, 2009-05-17 at 10:41 -0700, Bobby Roberts wrote: > from django import forms > from django.contrib.auth.models import User > > # pull a recordset of the users > userdata = User.objects.all() > > def myuserlist(self): > for i in userdata: > self[i.id]='%s %s' %(i.first_name,i.la

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
> ...     users = forms.ModelMultipleChoiceField( > ...         queryset=User.objects, > ...         widget=forms.CheckboxSelectMultiple, > ...         required=True) > ...>>> User(username='sdc').save() > >>> User(username='bobby').save() dude you rock... i totally missed this. Does exactly w

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
> oops, please modify the line from "self[i.id]='%s %s', > (i.first_name,i.last_name)"  to "self[i.id]='%s %s' % > (i.first_name,i.last_name) " this results in the same issue: from django import forms from django.contrib.auth.models import User # pull a recordset of the users userdata = User.o

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Lokesh
oops, please modify the line from "self[i.id]='%s %s', (i.first_name,i.last_name)" to "self[i.id]='%s %s' % (i.first_name,i.last_name) " On May 17, 10:28 pm, Bobby Roberts wrote: > > Try this below code. I guess this will solve your purpose > >  # pull a recordset of the users > >  userdata = a

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
> Try this below code. I guess this will solve your purpose > >  # pull a recordset of the users >  userdata = auth_user.objects.all() > >  def user_filler(self): >      for i in userdata: >          self[i.id] = '%s, %s', (i.firstname, i.lastname) >      return self.items() > from django import

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Lokesh
Hi, Try this below code. I guess this will solve your purpose # pull a recordset of the users userdata = auth_user.objects.all() def user_filler(self): for i in userdata: self[i.id] = '%s, %s', (i.firstname, i.lastname) return self.items() Regards, Lokesh On May 17, 9:41

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
> p=Country.objects.all()   -> capturing all the records from > Country table > def country_filler(self):    -> function  to generate a country > list which we are going to fetch from the records >     incr = 0 >     for i in p: >        self[incr] = i.country >        incr = incr+1 >    

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Alex Gaynor
On Sun, May 17, 2009 at 11:24 AM, Lokesh wrote: > > Hi Alex, > > Then I can go ahead with required=false attribute to avoid form > validation and validation should be taken care by program. > Correct me if I am wrong. > > Regards, > Lokesh > > > >incr = 0 > > >for i in p: > > > self

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Lokesh
Hi Alex, Then I can go ahead with required=false attribute to avoid form validation and validation should be taken care by program. Correct me if I am wrong. Regards, Lokesh > >    incr = 0 > >    for i in p: > >       self[incr] = i.country > >       incr = incr+1 > >    return self.items() >

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Alex Gaynor
On Sun, May 17, 2009 at 11:16 AM, wrote: > > Hi, > > p=Country.objects.all() -> capturing all the records from > Country table > def country_filler(self):-> function to generate a country > list which we are going to fetch from the records >incr = 0 >for i in p: > sel

Re: Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread lokeshmaremalla
Hi, p=Country.objects.all() -> capturing all the records from Country table def country_filler(self):-> function to generate a country list which we are going to fetch from the records incr = 0 for i in p: self[incr] = i.country incr = incr+1 return self.i

Seeking Example of MultipleChoiceField Example with dynamic Choices

2009-05-17 Thread Bobby Roberts
Hi. I'm needing to learn how to dynamically pull data out of the database and pass it as a CHOICES argument in my form. I want to pull a recordset of options, dump it into the choices and pass it to the form etc. Can someone out there lend me a hand? I'd like the options on the form to be chec

Re: dynamic choices iterator in model field

2008-11-19 Thread Malcolm Tredinnick
On Wed, 2008-11-19 at 09:42 -0800, Delta20 wrote: > A model field may have a 'choices' option to which you assign an > iterable object -- typically a list, but this can also be an iterable > function. Is there a way to assign a class method/function rather than > a module function? No. Python di

dynamic choices iterator in model field

2008-11-19 Thread Delta20
A model field may have a 'choices' option to which you assign an iterable object -- typically a list, but this can also be an iterable function. Is there a way to assign a class method/function rather than a module function? Here's what I'm trying to do: I have a model, "Ticket" that can be in an

Re: dynamic choices for views/newforms

2008-06-29 Thread John Aherne
Daniel Roseman wrote: > On Jun 29, 2:24 pm, John Aherne <[EMAIL PROTECTED]> wrote: > >> OK. I did some more experimenting with ModelChoiceField and my table. >> >> Surprise. It worked when I thought it would not. Why did it work. By >> luck in my model I had the __unicode__ function return the

Re: dynamic choices for views/newforms

2008-06-29 Thread Daniel Roseman
On Jun 29, 2:24 pm, John Aherne <[EMAIL PROTECTED]> wrote: > OK. I did some more experimenting with ModelChoiceField and my table. > > Surprise. It worked when I thought it would not. Why did it work. By > luck in my model I had the __unicode__ function return the right value. > So now I could see

Re: dynamic choices for views/newforms

2008-06-29 Thread John Aherne
John Aherne wrote: > Daniel Roseman wrote: > >> On Jun 29, 11:34 am, John Aherne <[EMAIL PROTECTED]> wrote: >> >> >>> I've been looking at django for a while. Been through the tutorial a few >>> times and read 2 books several times and am still trying to find out how >>> some things wor

Re: dynamic choices for views/newforms

2008-06-29 Thread John Aherne
Daniel Roseman wrote: > On Jun 29, 11:34 am, John Aherne <[EMAIL PROTECTED]> wrote: > >> I've been looking at django for a while. Been through the tutorial a few >> times and read 2 books several times and am still trying to find out how >> some things work. >> >> Instead of an empty form on fi

Re: dynamic choices for views/newforms

2008-06-29 Thread Daniel Roseman
On Jun 29, 11:34 am, John Aherne <[EMAIL PROTECTED]> wrote: > I've been looking at django for a while. Been through the tutorial a few > times and read 2 books several times and am still trying to find out how > some things work. > > Instead of an empty form on first loading, I would like to be ab

dynamic choices for views/newforms

2008-06-29 Thread John Aherne
I've been looking at django for a while. Been through the tutorial a few times and read 2 books several times and am still trying to find out how some things work. Instead of an empty form on first loading, I would like to be able to fill out some selection lists with data pulled from a databa

Re: How to use newforms ChoiceField to show dynamic choices

2008-01-25 Thread ikks
I have mod_python and I'm using ModelChoiceField, but I'm not getting the expected results, when I change my queryset and the second has elements not present on the original queryset, it displays the choices but doesn't validate properly, complaining about the option not being valid for the set.

Re: How to use newforms ChoiceField to show dynamic choices

2008-01-25 Thread Artiom Diomin
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 YourCoolForm(forms.ModelForm): ~choices_field = forms.ModelChoiceField( ~queryset=UserProfile.objects.all()) ~def__init__(self, **kwargs): ~ super(YourCoolForm, self).__init__(**kwargs) ~ self.fields['choices_field'].q

Re: How to use newforms ChoiceField to show dynamic choices

2008-01-24 Thread Nathaniel Whiteinge
ModelChoiceField. Currently not documented, but here's example code. Use your browser's find for "ModelChoiceField". http://www.djangoproject.com/documentation/models/model_forms/ On Jan 24, 9:47 pm, shabda <[EMAIL PROTECTED]> wrote: > I want to use the ChoiceField to show choices depending on

How to use newforms ChoiceField to show dynamic choices

2008-01-24 Thread shabda
I want to use the ChoiceField to show choices depending on a query set. For exmple the ChoiceField must get all active Users and them show them in a drop down, something like what happens in Admin. How can I do that? --~--~-~--~~~---~--~~ You received this message b

Re: dynamic choices in a ChoiceField

2008-01-13 Thread James Bennett
2008/1/13 Alex Koshelev <[EMAIL PROTECTED]>: > When you explicitly write list in choices it evaluates at module > import type. To avoid this write function and pass it as 'choices' > parameter Or... deck = forms.ModelChoiceField(queryset=Deck.objects.all()) -- "Bureaucrat Conrad, you are tec

Re: dynamic choices in a ChoiceField

2008-01-13 Thread Alex Koshelev
Thanks. My mistake On 13 янв, 21:39, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Alex Koshelev wrote: > > When you explicitly write list in choices it evaluates at module > > import type. To avoid this write function and pass it as 'choices' > > parameter > > > def get_choices(): > > [(d.id,d.

Re: dynamic choices in a ChoiceField

2008-01-13 Thread Fredrik Lundh
Alex Koshelev wrote: > When you explicitly write list in choices it evaluates at module > import type. To avoid this write function and pass it as 'choices' > parameter > > def get_choices(): > [(d.id,d.name) for d in Deck.objects.all()] (adding a return statement might be a good idea /F)

Re: dynamic choices in a ChoiceField

2008-01-13 Thread Alex Koshelev
When you explicitly write list in choices it evaluates at module import type. To avoid this write function and pass it as 'choices' parameter def get_choices(): [(d.id,d.name) for d in Deck.objects.all()] #... deck = forms.ChoiceField(required=True,choices = get_choices ) When this function

dynamic choices in a ChoiceField

2008-01-13 Thread Julian
Hi there, I have cards and decks, decks have ManyToMany cards, and if you want to add a card, you have to chose a deck; quite simple. my forms.py contains something like that: class CardForm(forms.Form): deck = forms.ChoiceField(required=True,choices=[(d.id,d.name) for d in Deck.objects.all

Re: newforms and dynamic choices

2007-01-13 Thread Honza Král
On 1/13/07, Brian Victor <[EMAIL PROTECTED]> wrote: Let's say there's a Room model. And let's say there's a ManyToMany relationship with User to specify which users can schedule certain rooms. How should a person in such a circumstance create a SelectField on a form with a user's rooms as choi

newforms and dynamic choices

2007-01-13 Thread Brian Victor
Let's say there's a Room model. And let's say there's a ManyToMany relationship with User to specify which users can schedule certain rooms. How should a person in such a circumstance create a SelectField on a form with a user's rooms as choices? Or more generally, how should I go about changin

Re: Dynamic choices

2006-02-14 Thread Chetan Vaity
Thanks Amit and Adrian,I think I'll do something like what Amit said or write a custom manipulator.- ChetanOn 2/8/06, Adrian Holovaty < [EMAIL PROTECTED]> wrote:On 2/8/06, Amit Upadhyay < [EMAIL PROTECTED]> wrote:> > What I notice is that whenever an entry is added to LDAP, it is not> reflected in

Re: Dynamic choices

2006-02-08 Thread Adrian Holovaty
On 2/8/06, Amit Upadhyay <[EMAIL PROTECTED]> wrote: > > What I notice is that whenever an entry is added to LDAP, it is not > reflected in the SelectField drop-down on the create form for the model. But > if I simply restart the Apache httpd server, the drop-down is correctly > populated. > > > >

Re: Dynamic choices

2006-02-08 Thread Amit Upadhyay
On 2/8/06, Chetan Vaity <[EMAIL PROTECTED]> wrote: class MyModel(meta.Model):     id = meta.AutoField(primary_key = True)     name = meta.CharField(maxlength=20, unique=True)     location = meta.CharField(maxlength=100, choices=getLocationChoices()) What I notice is that whenever an entry is added

Dynamic choices

2006-02-08 Thread Chetan Vaity
Hi all, I have a model which looks somethng like: class MyModel(meta.Model):     id = meta.AutoField(primary_key = True)     name = meta.CharField(maxlength=20, unique=True)     location = meta.CharField(maxlength=100, choices=getLocationChoices()) and getLocationChoices() is a function defined

Re: dynamic choices

2005-10-20 Thread stava
stava wrote: > I'm having a bit of a problem with dynamic choices. I'm working on a > simple timesheet system where I've extended the auth.users with a > couple of fields including something I call "primary group": > > def getUsers(group = None): > u

dynamic choices

2005-10-17 Thread stava
I'm having a bit of a problem with dynamic choices. I'm working on a simple timesheet system where I've extended the auth.users with a couple of fields including something I call "primary group": def getUsers(group = None): users = [] if group is None: for u