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
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:
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',
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
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
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
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
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:
>
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
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
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
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
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
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
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
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
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
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
>>>
>>>
> 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
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
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
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
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
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
> ... 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
> 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
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
> 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
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
> 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
>
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
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()
>
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
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
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
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
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
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
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
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
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
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
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
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.
-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
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
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
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
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.
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)
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
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
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
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
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
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.
> >
> >
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
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
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
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
60 matches
Mail list logo