ModelChoiceField

2010-06-24 Thread Tran Cao Thai
Hi all, is there any way to use the ModelChoiceField without any value in it? I tried to set query = None but it gave an error while rendering the html page -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, sen

ModelChoiceField

2010-06-27 Thread Tran Cao Thai
hi all, i am trying to write auto populated select box by using jquery and ModelChoiceField. I have 2 variables cates and subcates, the first one take all the objects from the Category model, the second takes None object (Subcategory.objects.none ()). at first the html rendering is fine. When i

Validate ModelChoiceField

2009-09-16 Thread alivad
Hi: in the example this link http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other additional validation is performed cc_myself and subject fields, could give me an example to validate a field of type ModelChoiceField Thanks

ModelChoiceField help

2009-05-20 Thread Bobby Roberts
Hi Group. Please look at this snippet from my forms. It uses two ModelChoiceFields as shown below. Each database table currently has 2 records. On the webpage, when the form is being called, the options are like this: Template object Template object and PageCategory object PageCategory obje

ModelChoiceField choice_cache

2009-05-25 Thread robin
I was trying to find a way to get ModelChoiceFields to use an already cached Model, and I came across in django/forms/models.py , under class ModelChoiceField, a variable called: self.choice_cache=None class ModelChoiceIterator seems to be the only thing that plays with it, but with or without

Re: ModelChoiceField

2010-06-24 Thread Oleg Lomaka
On 6/25/10 8:25 AM, Tran Cao Thai wrote: is there any way to use the ModelChoiceField without any value in it? I tried to set query = None but it gave an error while rendering the html page Use EmptyQuerySet. field = ModelChoiceField(queryset=YouMode.objects.none()) http

Re: ModelChoiceField

2010-06-25 Thread Tran Cao Thai
Thank you very much. I missed that part in the documentation On Fri, Jun 25, 2010 at 4:54 PM, Oleg Lomaka wrote: > On 6/25/10 8:25 AM, Tran Cao Thai wrote: > >> is there any way to use the ModelChoiceField without any value in it? I >> tried to set query = None but it g

ModelChoiceField Question

2010-07-28 Thread Carlos Daniel Ruvalcaba Valenzuela
Hello list, I was wondering which would be the best way to handle this situation with ModelChoiceFields: I have a form with a ModelChoiceField, the options presented in this field may change at the view depending on the user, however, ModelChoiceField requires the queryset to be given as a

ModelChoiceField problems

2011-03-17 Thread Thiago Carvalho D' Ávila
Hi, I'm making one app with 3 classes: emploee, company and department. 1- When I edit an emploee I need to know his company, and after to have a field with all the departments from the selected company. But when I use ModelChoiceField I see all departments from all companies. 2- Another pr

Dynamic ModelChoiceField

2007-05-31 Thread sorrison
I am using a ModelChoiceField (default_project) in a form and want the initial queyset to change when the form is created. I've tried doing it like this: forms.py -- class UserAccountForm(forms.Form): . default_project = forms.ModelChoiceField(queryset=Project.object

Custom ModelChoiceField muddle

2008-09-30 Thread Donn
Hi, I have a modelForm that has a foreign key. I want the control to be a link instead of a element. This I have managed. It opens a div which lets me pick a value from a long list. The problem I am having is feeding the chosen value back into the original form. I can't figure out which clean

Tree in ModelChoiceField

2009-07-06 Thread Oraculum
Input()) nome = CharField(widget=TextInput(attrs={'class':'textInput required'}), required=True) pai = ModelChoiceField(PlanoConta.objects.none(), empty_label=None) def __init__(self, *args, **kwargs): super(PlanoContaForm, self).__init__(*args, **kwargs)

ModelChoiceField, Cascading Selections

2008-05-29 Thread Adi
queryset to League.objects.all(). I don't want to do this cos the League data is huge. 2. Since the fields don't bind to the values, when the form get redisplayed, the values are not redisplayed. I am struggling with the ModelChoiceField in general as well. --~--~-~--~~---

ModelChoiceField option values

2008-06-07 Thread Mihai Damian
I'm using a ModelChoiceField on a form and it seems the value attributes of the generated option tags are simply their numeric order in the queryset. How can I set the value attribute to some useful information like id or the __unicode__ representation itself? T

Re: ModelChoiceField help

2009-05-20 Thread Alex Gaynor
ed_data['page_category_id'] >return data > >def clean_template_id(self): >data=self.cleaned_data['template_id'] >return data > > > > Take a look at label_from_instance: http://docs.dj

Re: ModelChoiceField help

2009-05-20 Thread Bobby Roberts
> Take a look at > label_from_instance:http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield > > Alex > yeah I'm lookin at that but it makes no sense to me. Here's what i have and it's not working: from django import forms from web_pages.m

Re: ModelChoiceField help

2009-05-20 Thread Alex Gaynor
On Wed, May 20, 2009 at 12:32 PM, Bobby Roberts wrote: > > > You aren't actually using that Field though, you need to use it in place > of > > ModelChoiceField where you want that behavior. > > > > Alex > > > here's what i'

Re: ModelChoiceField help

2009-05-20 Thread Alex Gaynor
On Wed, May 20, 2009 at 10:38 AM, Bobby Roberts wrote: > > > Take a look at label_from_instance: > http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield > > > > Alex > > > > yeah I'm lookin at that but it makes no sense to me. &g

Re: ModelChoiceField help

2009-05-20 Thread Bobby Roberts
ur form (in the file), otherwise the Field > won't be defined when you go to use it. > > Alex Alex - I really appreciate your help. I made the changes you suggested and it's shown here: class MyModelChoiceField (ModelChoiceField): def label_from_instance(self,o

Re: ModelChoiceField help

2009-05-20 Thread Alex Gaynor
s a note, you're going to want to have the > > MyModelChoiceField class before your form (in the file), otherwise the > Field > > won't be defined when you go to use it. > > > > Alex > > > > Alex - > > I really appreciate your help. I mad

Re: ModelChoiceField help

2009-05-20 Thread Bobby Roberts
> You aren't actually using that Field though, you need to use it in place of > ModelChoiceField where you want that behavior. > > Alex here's what i've got: class FrmWebPage (forms.Form): active = forms.ChoiceField(required=True, choices=active_choices, wid

Re: ModelChoiceField help

2009-05-20 Thread Bobby Roberts
> Your class should inherit from "forms.ModelChoiceField", not just > ModelChocieField. > > Alex Ok i'm getting somewhere! Thanks for your patience. I'm still finding my python / django legs. This populates the dropbox with My Object #1 My Object #2 My Object #3 I see why it's dong that in

Re: ModelChoiceField help

2009-05-20 Thread Alex Gaynor
On Wed, May 20, 2009 at 2:05 PM, Bobby Roberts wrote: > > > > Your class should inherit from "forms.ModelChoiceField", not just > > ModelChocieField. > > > > Alex > > > Ok i'm getting somewhere! Thanks for your patience. I'm still > finding my python / django legs. This populates the dropbox w

Re: ModelChoiceField help

2009-05-20 Thread Bobby Roberts
> Sure, label_for_instance gets the object itself, with all it's fields.  So > isntead of returning the string with the id number, change it to return: > obj.name. > > Alex PERFECT! Thanks a lot! --~--~-~--~~~---~--~~ You received this message because you are subs

ModelChoiceField queryset option

2009-06-11 Thread Bobby Roberts
hi group i'm trying to create a drop box that is populated with a distinct list of values from a certain field (fieldname=page_plaque) in the table. Here is what i have in my forms.py class PagePlaqueModelChoiceField (forms.ModelChoiceField): def label_from_instance(self,obj):

HiddenInput for ModelChoiceField

2009-12-12 Thread Aaron
Say I have this model: model Foo(models.Model): bar = models.ForeignKey(Baz) I have a ModelForm for Foo (FooModelForm). However, instead of having a ModelChoiceField for bar, I want a single bar object in a hidden field that's specified when creating the FooModelForm. m

Re: ModelChoiceField Question

2010-07-28 Thread euan.godd...@googlemail.com
I believe ModelChoiceField is meant to be used with ModelForm. I'd stick to one or the other. Either use ModelForm and let it do the work, or use Form and do the work yourself rather than trying to get ModelChoiceField to work. Euan On 29 July, 05:23, Carlos Daniel Ruvalcaba Valenzuela

Re: ModelChoiceField Question

2010-07-29 Thread Daniel Roseman
On Jul 29, 5:23 am, Carlos Daniel Ruvalcaba Valenzuela wrote: > Hello list, > > I was wondering which would be the best way to handle this situation > with ModelChoiceFields: > > I have a form with a ModelChoiceField, the options presented in this > field may change at the

Re: ModelChoiceField Question

2010-08-01 Thread Steve Holden
On 7/29/2010 8:56 AM, Daniel Roseman wrote: > On Jul 29, 5:23 am, Carlos Daniel Ruvalcaba Valenzuela > wrote: >> Hello list, >> >> I was wondering which would be the best way to handle this situation >> with ModelChoiceFields: >> >> I have a form with a

Re: ModelChoiceField problems

2011-03-17 Thread Shawn Milochik
I believe you can filter them using ModelAdmin.formfield_for_choice_field. Check out the docs here: http://docs.djangoproject.com/en/1.2/ref/contrib/admin/ Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email

Re: ModelChoiceField problems

2011-03-18 Thread Thiago Carvalho D' Ávila
Is there any secury issues by using adminfield in normal user forms? 2011/3/17 Shawn Milochik > I believe you can filter them using ModelAdmin.formfield_for_choice_field. > > Check out the docs here: > http://docs.djangoproject.com/en/1.2/ref/contrib/admin/ > > Shawn > > -- > You received this m

Re: ModelChoiceField problems

2011-03-18 Thread Thiago Carvalho D' Ávila
The formfield_for_choice_field method can be overridden to change the default formfield for a field that has declared choices. For example, if the choices available to a superuser should be different than those available to regular staff. That doesn't seem to be the case, because the staff and th

Re: ModelChoiceField problems

2011-03-19 Thread vac
I had similar problem and i sort it out by overloading __init__ func of my form and change queryset method of a field (ModelChoiceField), i.e.: self.fields[depatment].queryset = self.fields[depatment].queryset.filter(company=selectedcompany) Maybe it will help You with finding right solution. On

Re: Dynamic ModelChoiceField

2007-06-01 Thread Dwarf
On Jun 1, 3:27 am, sorrison <[EMAIL PROTECTED]> wrote: > I am using a ModelChoiceField (default_project) in a form and want the > initial queyset to change when the form is created. > > I've tried doing it like this: > > forms.py -- >

ModelChoiceField on newforms

2007-08-17 Thread james_027
hi, while learning and experimenting with forms ... one should use ModelChoiceField in order to let newforms bind the value on a foreignkey field of a model. My concern is that in the real world, you usually don't use to let the user chose the value to be filled especially if the li

ModelChoiceField default value

2007-09-17 Thread Rufman
how can i make one of the options in a select the default. (i previously changed the select widget so that it only shows a selection of options). my code: ModifyComment.base_fields['fk_bullet'] = forms.ModelChoiceField(queryset=Bullet.objects.filter(fk_day=day_id)) i what one of the options in t

newforms ModelChoiceField queryset

2007-11-06 Thread Gonzalo Delgado
Hello there, I'm using Django 0.96 here. I've got a couple of models related by a ForeignKey that look more or less like this: class Server(models.model): name = models.CharField(maxlength=20) users = models.ManyToManyField(User) class Ticket(models.model): des

ModelChoiceField with Unique Results

2008-09-22 Thread BobZ
What I'm trying to do seems relatively simple, but I have yet to find a proper solution for it. I'm trying to query a list of years from a database of registered vehicles in my county and display them in a drop-down select menu in a form. Since the registered vehicles database has many cars of

Re: Custom ModelChoiceField muddle

2008-09-30 Thread Donn
Perhaps if I ask it in a different way: 1. A 'book' has a title (string) and an author (foreign key). 2. I use a ModelForm from the model. 3. I want the 'author' form-control to look like this: Author:__ [click here to choose or add an author] 4. When you click the link it opens a div. 5. The

Re: Custom ModelChoiceField muddle

2008-10-01 Thread TiNo
If you do all that stuff with jquery, why not have jquery hide the original select (or modify it for that matter), and on select of an author, have jquery set the selected author as 'selected' in the dropdown box? That way there is no need for a custom validation or insertion, and when somebody has

Re: Custom ModelChoiceField muddle

2008-10-01 Thread Donn
Bump \d --~--~-~--~~~---~--~~ 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

Re: Custom ModelChoiceField muddle

2008-10-01 Thread Donn
On Wednesday, 01 October 2008 10:28:13 TiNo wrote: > If you do all that stuff with jquery, why not have jquery hide the original > select (or modify it for that matter), and on select of an author, have > jquery set the selected author as 'selected' in the dropdown box? That way > there is no need

Re: Custom ModelChoiceField muddle

2008-10-01 Thread Karen Tracey
On Wed, Oct 1, 2008 at 9:39 AM, Donn <[EMAIL PROTECTED]> wrote: > I am expecting there to be at least hundreds of authors, perhaps thousands. > It > makes no sense to me to stream them all into a select control in the first > place. > > I am aiming for a new kind of control that let's one page/fil

Re: Custom ModelChoiceField muddle

2008-10-01 Thread Donn
On Wednesday, 01 October 2008 16:13:18 Karen Tracey wrote: > looking-glass icon on > an admin change page where the ForeignKey field has been included in > raw_id_fields. Thanks for the lead! \d --~--~-~--~~~---~--~~ You received this message because you are subsc

ModelChoiceField and initial value

2009-02-23 Thread Brandon Taylor
Hi everyone, What's the trick to getting a ModelChoiceField to use the first object in a QuerySet as the initial value to get rid of -? If I do: qs = Model.objects.all() my_field = forms.ModelChoiceField(queryset=qs, initial=qs[0]) I still get -- as the first choice.

Re: ModelChoiceField, Cascading Selections

2008-05-29 Thread Richard Dahl
objects.none(). How do I make the > values bind to the fields without having to resort to changing the > queryset to League.objects.all(). I don't want to do this cos the > League data is huge. > > 2. Since the fields don't bind to the values, when the form get > redispla

Re: ModelChoiceField option values

2008-06-09 Thread Adi
The text displayed in the drop down comes from the __str__ method of the referenced model. So, just implement the __str__ method in the model that your ModelChoiceField references, and the display will show you that. On Jun 7, 10:55 am, Mihai Damian <[EMAIL PROTECTED]> wrote: > I&

Re: ModelChoiceField option values

2008-06-10 Thread Mihai Damian
10x, I eventualy solved the problem. I think I was doing some caching and so the values didn't resemble the id's I was reading from the database --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To

ModelChoiceField setting value manually

2008-06-26 Thread mwebs
Hello, I try to set data for a ModelChoiceField() manually. This means the data is not in my db, so it s not in a Queryset. my form: class PictureForm(forms.Form): image = forms.ImageField(label='Picture') gallery= MyModelChoiceField(models.Gallery.ob

Validation Problem with ModelChoiceField

2008-06-26 Thread mwebs
l='Picture') gallery= MyModelChoiceField(models.Gallery.objects.none(), empty_label=None) __ View: picture_form = forms.PictureForm() picture_form.fields['gallery'].queryset = Gallery.objects.filter(...) It displays all

ModelChoiceField and dynamic Querysets

2008-09-05 Thread mwebs
With the ModelChoiceFiled you can represent relationships between models. So my form looks something like this: class MyForm(forms.Form): name = forms.CharField() trials = forms.ModelChoiceField(...) According to the documentation I have to pass the queryset to the modelchoicefield

ModelChoiceField - remove empty-value

2008-09-05 Thread mwebs
Hello, I use a modelchoicefield and want to remove the entry that represents "no item selected"(--), because in my scenario I will only allow to select between existing entries. Is there a way to do this? Thanks, -Toni --~--~-~--~~~---~--~~ Yo

ModelChoiceField - large lookup tables

2009-03-24 Thread PNM
ble with thousands of rows into a ModelChoiceField. The postcode field changes relatively seldom, so a sensible solution would seem to be some sort of passive display-only field which mirrors the choice field's functionality (show the link's __unicode__ and hold the link's pk for form va

change query for ModelChoiceField

2009-05-11 Thread adrian
I want to create a form with a select box populated from a query that I pass from the view. For example: if country == 'Canada': methods = ShippingMethod.objects.filter( delivery_time__lte=time_avail_hours, abbrev__contains='SC' )

Re: ModelChoiceField queryset option

2009-06-11 Thread Alex Gaynor
On Thu, Jun 11, 2009 at 12:13 PM, Bobby Roberts wrote: > > hi group > > i'm trying to create a drop box that is populated with a distinct list > of values from a certain field (fieldname=page_plaque) in the table. > Here is what i have in my forms.py > > > class PagePlaqueModelChoiceField (f

Re: ModelChoiceField queryset option

2009-06-11 Thread Bobby Roberts
> The issue is the line: WebPage.objects.filter(page_plaque!='').  The > queryset syntax doens't use the != operator anywhere.  To do != operations > you need to instead do WebPage.objects.exclude(page_plaque=''). > ok that got past the error but there are dupes in there. Is there a way to pull

Re: ModelChoiceField queryset option

2009-06-11 Thread googletorp
Hi. You should take a read on the queryset api, that would help you a lot In the furture. For distinct values add .distinct() so you fx get ...filter(...).distinct() ~Jakob On Jun 11, 7:28 pm, Bobby Roberts wrote: > > The issue is the line: WebPage.objects.filter(page_plaque!='').  The > > quer

Re: ModelChoiceField queryset option

2009-06-11 Thread Bobby Roberts
> Hi. > You should take a read on the queryset api, that would help you a lot > In the furture. For distinct values add .distinct() so you fx get > ...filter(...).distinct() > > ~Jakob Jakob - I've read the docs and know about distinct. The issue here is that a modelcho

Re: HiddenInput for ModelChoiceField

2009-12-14 Thread Aaron
y last post. On Dec 12, 11:03 am, Aaron wrote: > Say I have this model: > > model Foo(models.Model): >     bar = models.ForeignKey(Baz) > > I have a ModelForm for Foo (FooModelForm). However, instead of having > a ModelChoiceField for bar, I want a single bar object in a h

How to customize ModelChoiceField?

2010-05-29 Thread shaunc
esn't seem to be applicable. What I think I want to do is override the description field in the RateForm to be a custom derivative of ModelChoiceField... but I'm not sure where to intercept validation, etc. -- Indeed the documentation seems to skip over ModelChoiceField altogether. Can anyon

bound form with ModelChoiceField

2011-04-21 Thread ekms
Hello, I have a form with a ModelChoiceField, and when I want to create a new bound form using the first form cleaned_data (that I stored in a session before), I get an error when rendering the template ("Caught TypeError while rendering: int() argument must be a string or a number"

Many2many field and ModelChoiceField

2011-05-09 Thread Roodie
Hello, I have a small issue, I am sure the solution is simple, but I couldn't find it (I blame Monday). I have a model with a Many2Many field, and I have a few forms for editing that model. Everything is working fine there. In one specific case however I have to produce a form where the user can s

ModelChoiceField with multiple databases

2011-12-21 Thread Brian Craft
Is there an easy way to use a ModelChoiceField with multiple databases? The only thing I've seen that looks promising is overriding the form __init__ and setting the queryset for the field. Seems kinda clunky. -- You received this message because you are subscribed to the Google Groups &q

Distinct Values in ModelChoiceField

2012-08-19 Thread Joseph Mutumi
Hello, I have a model that has a foreign key field that I want to use in a form as a select box. That particular field at times appears multiple times in the database. How do I make it only have distinct values? This is a snippet, drop down will have repeated values if same color is entered: cla

Dynamic queryset to ModelChoiceField

2008-04-14 Thread shabda
t work, of course, as ModelChoiceField has queryset as required argument. So I have to do something like, class SetDefaultForm(forms.Form): topics = forms.ChoiceField() def __init__(self, user): super(SetDefaultForm, self).__init__() self.fields['topics'].choices=

Re: ModelChoiceField on newforms

2007-08-17 Thread Malcolm Tredinnick
On Fri, 2007-08-17 at 08:22 +, james_027 wrote: > hi, > > while learning and experimenting with forms ... one should use > ModelChoiceField in order to let newforms bind the value on a > foreignkey field of a model. My concern is that in the real world, you > usually don&

Variable choices in ModelChoiceField

2007-08-17 Thread [EMAIL PROTECTED]
Hi all, I have a newform GroupSelectionForm with: group_id = forms.ModelChoiceField(Group.objects.all()) where users are supposed to choose their primary group. However I only want to offer them groups in which they have membership. I.e. instead of Group.objects.all() do something like Group

Re: ModelChoiceField default value

2007-09-17 Thread Richard Dahl
initial works for me, however, you must set the initial by the id of the record not the instance, i.e. forms.ModelChoiceField(queryset=Bullet.objects.filter(fk_day=day_id), initial = Bullet.objects.get(pk = day_id).id) -richard On 9/17/07, Rufman <[EMAIL PROTECTED]> wrote: > > > how can i make

Re: newforms ModelChoiceField queryset

2007-11-06 Thread Chris Brand
Gonzalo Delgado wrote: > > The question is: why doesn't something like this work: > > ticketform.fields['server'].queryset = > Server.objects.filter(users=request.user) > ? > It doesn't end up on any error, but the rendered form doesn't filter out the > server choices.. any clue? > >

Re: newforms ModelChoiceField queryset

2007-11-06 Thread Gonzalo Delgado
El Tue, 06 Nov 2007 10:28:39 -0800 Chris Brand <[EMAIL PROTECTED]> escribió: > > Gonzalo Delgado wrote: > > > > The question is: why doesn't something like this work: > > > > ticketform.fields['server'].queryset = > > Server.objects.filter(users=request.user) > > ? > > It doesn't end up on

setting newforms ModelChoiceField "selection"

2007-02-27 Thread grahamu
I'm struggling with a newforms issue. Specifically I'm trying to pre- select an option in a ModelChoiceField and I cannot figure out how this can be accomplished. Here are the code snippets: class Account(models.Model): title = models.CharField(maxlength=30, unique=True

Filtering ModelChoiceField for InlineFormset

2019-09-26 Thread IWilliams
Hi, I would like to use ModelChoiceField in the following ways: models.py class Project(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True) ... class Profile(models.Model): project = models.ForeignKey(Project, on_delete

ModelChoiceField get selected value

2019-12-02 Thread sum abiut
How do I get the value of a selected model choice field? I have a model that has a field 'user' as a foreignKey and I am trying to figure out how to get the value of a user that was selected. I have a form that looks like below, [image: image.png] class update_entitlement_form(forms.ModelForm):

Re: ModelChoiceField with Unique Results

2008-09-22 Thread [EMAIL PROTECTED]
You can try something like this: class SearchForm(forms.ModelForm): year = forms.ChoiceField() def __init__(self, *args, **kwargs): super(SearchForm, self) .__init__(*args, **kwargs) self.fields['year'].choices = \ set([(obj.year, obj.year) for obj in \

Re: ModelChoiceField with Unique Results

2008-09-22 Thread [EMAIL PROTECTED]
You can try something like this: class SearchForm(forms.ModelForm): year = forms.ChoiceField() def __init__(self, *args, **kwargs): super(SearchForm, self) .__init__(*args, **kwargs) self.fields['year'].choices = \ set([(obj.year, obj.year) for obj in \

Re: ModelChoiceField with Unique Results

2008-09-22 Thread BobZ
Thanks dmorozov, that worked fine in the sense that it returned only unique years in a select box, but it still didn't order them properly (getting non-duplicate years as 1961, 1931, 2000, 1975, 1995, etc.). Somehow the order_by section of "set([(obj.year, obj.year) for obj in Vehicle.objects.al

Re: ModelChoiceField - remove empty-value

2008-09-22 Thread Brian Neal
On Sep 5, 11:19 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Fri, 2008-09-05 at 03:11 -0700, mwebs wrote: > > Hello, > > > I use amodelchoicefieldand want to remove the entry that represents > > "no item selected"(--), because in my > > scenario I will only allow to select between ex

Re: ModelChoiceField with Unique Results

2008-09-22 Thread Daniel Roseman
On Sep 22, 10:58 pm, BobZ <[EMAIL PROTECTED]> wrote: > Thanks dmorozov, that worked fine in the sense that it returned only > unique years in a select box, but it still didn't order them properly > (getting non-duplicate years as 1961, 1931, 2000, 1975, 1995, etc.). > > Somehow the order_by sectio

Re: ModelChoiceField with Unique Results

2008-09-23 Thread BobZ
Thanks Daniel. I've found solutions similar to yours in other threads on the net, and everytime I test them, I literally get no form at all in my rendered template. My template appears to have all the correct code in it as you can see in the link "search.html" at the bottom of this post. Looking

Re: ModelChoiceField with Unique Results

2008-09-23 Thread BobZ
I had SOME luck with "queryset=Vehicle.objects.filter(year=True)" in that the form actually rendered in my template, but the year select box is empty now. All other select boxes load fine (Make and Model) with their data...only year still won't work. On Sep 23, 10:44 am, BobZ <[EMAIL PROTECTED]>

Re: ModelChoiceField with Unique Results

2008-09-23 Thread Daniel Roseman
On Sep 23, 4:44 pm, BobZ <[EMAIL PROTECTED]> wrote: > Thanks Daniel.  I've found solutions similar to yours in other threads > on the net, and everytime I test them, I literally get no form at all > in my rendered template. > My template appears to have all the correct code in it as you can see >

Re: ModelChoiceField with Unique Results

2008-09-24 Thread BobZ
Wow, thank you so much Daniel. I totally get this now, and it works! Looks like I've sort of been skirting around this solution for a while but, being clueless as I can be sometimes with Django, I never knew what I could've been doing wrong. Thanks a lot for the help again. -Bob On Sep 23, 4:

Re: ModelChoiceField and initial value

2009-02-23 Thread Brandon Taylor
Solved: ModelChoiceField(empty_label=None) On Feb 23, 9:14 pm, Brandon Taylor wrote: > Hi everyone, > > What's the trick to getting a ModelChoiceField to use the first object > in a QuerySet as the initial value to get rid of -? > > If I do: > qs = Mode

ChoiceField, TypedChoiceField, ModelChoiceField and empty_label

2009-07-02 Thread ristretto.rb
Hello, I have stepped through code, and cruised the django docs, forums, and internet in general looking for how to setup an empty label with TypedChoiceField (or ChoiceField.) I suspected it would be done similar to the way it is done with ModelChoiceField. With ModelChoiceField, we can

Need help with a modelChoiceField

2009-08-07 Thread Bobby Roberts
ok here's my form: class ParseFileChoiceField (forms.ModelChoiceField): def label_from_instance (self,obj): return obj.ProcessFile class FrmParser (forms.Form): parsefile = ParseFileChoiceField(queryset=Upload.objects.filter (numrecs__exact=0),empty_label='Choose',required=True,w

dynamic value of a ModelChoiceField

2008-06-22 Thread [EMAIL PROTECTED]
In a form, I have a field defined as ModelChoiceField class myForm(forms.Form) myfield = forms.ModelChoiceField(MyClass.objects.all()) myfield2 = forms.CharField() My problem is that I cant seem to dynamically set the value that the user selected for this field. When ever, user edits the

Re: ModelChoiceField setting value manually

2008-06-26 Thread Adi
step. -Regards Adi On Jun 26, 12:27 pm, mwebs <[EMAIL PROTECTED]> wrote: > Hello, > > I try to set data for a ModelChoiceField() manually. This means the > data is not in my db, so it s not in a Queryset. > > my form: > > class PictureForm(forms.Form): >     i

Re: Validation Problem with ModelChoiceField

2008-06-27 Thread TiNo
Looking at the source, ModelChoiceField validates the given id against the initial queryset, where you provided an empty one. "models.Gallery.objects.none()" So no id's validate. I think changing none() to all() should make it work. TiNo On Jun 26, 9:01 pm, mwebs <[EMAIL

Problem testing ModelChoiceField in form

2008-07-17 Thread Florencio Cano
Hi! When I try to test a post to a form that have a ModelChoiceField form I get always a form error in that field "Select a valid choice". The form is this: class OperacionForm(forms.Form): ticker = forms.ModelChoiceField(Valor.objects.all()) fecha = forms.DateFi

Re: ModelChoiceField and dynamic Querysets

2008-09-05 Thread mwebs
This solved the problem: http://groups.google.com/group/django-users/browse_thread/thread/63c2058c7892f865 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to dj

Re: ModelChoiceField - remove empty-value

2008-09-05 Thread Malcolm Tredinnick
On Fri, 2008-09-05 at 03:11 -0700, mwebs wrote: > Hello, > > I use a modelchoicefield and want to remove the entry that represents > "no item selected"(--), because in my > scenario I will only allow to select between existing entries. Specify a default value

Re: ModelChoiceField - large lookup tables

2009-03-24 Thread Thomas Guettler
jango? > > My current example is an address>post/ZIP-code relationship where > Django's automatic field creation pulls in the whole postcode table > with thousands of rows into a ModelChoiceField. > > The postcode field changes relatively seldom, so a sensible solution

Re: change query for ModelChoiceField

2009-05-11 Thread google torp
This should fix it. def __init__(self, something, *args, **kwargs): super(ShippingMethodForm, self).__init__(*args, **kwargs) self.fields["ship_method"].queryset = ShippingMethod.objects.filter(something) when you initiate the form, you do it like this: form = ShippingMethodForm(

Re: change query for ModelChoiceField

2009-05-11 Thread adrian
I tried in the view: filter_string = "delivery_time__lte=time_avail_hours, abbrev__contains='SC'" formShip = ShippingMethodForm(filter_string) Then the form def is: class ShippingMethodForm(forms.Form): # tricky thing done here to change queryset based on ticket date and destination shi

Re: change query for ModelChoiceField

2009-05-11 Thread adrian
oops! missing the filter_string arg in __init__. After I added that, I get: ValueError .too many values to unpack On May 11, 4:27 pm, adrian wrote: > I tried in the view: > > filter_string = "delivery_time__lte=time_avail_hours, > abbrev__contains='SC'" > formShip = ShippingMethodForm(fil

Re: change query for ModelChoiceField

2009-05-11 Thread adrian
For the record, here's what works: In views.py: if country == 'Canada': delivery_time__lte=time_avail_hours abbrev__contains='SC' formShip = ShippingMethodForm(delivery_time__lte, abbrev__contains) Then in models.py: class ShippingMethodForm(forms.Form): # tricky

Re: change query for ModelChoiceField

2009-05-11 Thread krylatij
def __init__(self, *args, **kwargs): super(ShippingMethodForm, self).__init__(*args, **kwargs) if self.fields['country'].initial == 'Canada': filter_kwargs = { 'delivery_time__lte': time_avail_hours, 'abbrev__contains'='SC' } elif: ... else: .. self.fi

ModelChoiceField Work around or danger

2009-10-14 Thread Don Guernsey
I was struggling to find a solution to the ModelChoiceField looking up 100,000 students every time I wanted to add an RtI so I did the following. Can anyone find problems with this, or have an alternate solution...This does work though Instead of using an id I used a student_number as an

Re: How to customize ModelChoiceField?

2010-05-30 Thread shaunc
. In RateForm.clean I do the necessary search for the description model if there isn't one already defined, and setting the text of the model in any case. The override of ModelChoiceField may well be simple ... I started to go down that road before I realized it wasn't what I wanted in any

Re: bound form with ModelChoiceField

2011-04-21 Thread Andy McKay
On 2011-04-21, at 4:07 PM, ekms wrote: > So, what is the correct way to create a bound form of > ModelChoiceField? I could store request.POST or myform.data instead > of myform.cleaned_data, but I don't know if this is right. You are confusing me when you say a bound form of a Mo

  1   2   3   >