change select choices in django admin on select of another field

2013-02-11 Thread vijay shanker
Hi I have a model called Place, which is like this: class Place(models.Model): state = models.CharField(max_lengh=50, choices=STATE_CHOICES) city = models.Charfield(max_length=50) I want to populate select choices for repective city for state in admin, when the user selects

Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-20 Thread Huuuze
You da man. This worked perfectly out of the box. Thank you! On Jun 19, 5:54 pm, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote: > On Jun 19, 3:45 pm, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote: > > >                 if self.instance.state == 'processing': > >                     queryset =

Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-19 Thread Nathaniel Whiteinge
On Jun 19, 3:45 pm, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote: >                 if self.instance.state == 'processing': >                     queryset = queryset.exclude(state='new') The above lines aren't quite right ``self.instance`` is an instance of your ``SomeModel`` and presuming

Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-19 Thread Nathaniel Whiteinge
On Jun 19, 3:23 pm, Huuuze <[EMAIL PROTECTED]> wrote: > In this example, what if you wanted to selectively remove a value from > the choice list. For that you'll have to move the field declaration into the form's __init__ method:: class SomeForm(forms.ModelForm): class Meta:

Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-19 Thread Huuuze
In this example, what if you wanted to selectively remove a value from the choice list. For example, let's say the list contained New, In Process, and Closed. When an item is "In Process", it cannot revert back to "New". As such, "New" should not be displayed amongst the choices if "In

Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-08 Thread Berco Beute
Great! A cleaner solution. Thanks! Is there any effort underway for making overriding default widgets simpler? I think that's really needed (especially for beginner like me). 2B On Jun 8, 1:20 am, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote: > On Jun 7, 4:18 pm, Berco Beute <[EMAIL

Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-07 Thread Nathaniel Whiteinge
On Jun 7, 4:18 pm, Berco Beute <[EMAIL PROTECTED]> wrote: > Quite a lot of work for something so simple I agree that overriding default widgets is currently too much work. But here's a slightly shorter version that works in exactly the same way as your example:: class

Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-05 Thread Nathaniel Whiteinge
On Jun 5, 7:36 am, Berco Beute <[EMAIL PROTECTED]> wrote: > My model has a ForeignKey that renders as a SELECT field in HTML. The > problem is that there's an empty value ('-') that I would like > to hide. Presuming you are using newforms (i.e. not the Admin), then override the

Remove empty value ('---------') from HTML SELECT choices

2008-06-05 Thread Berco Beute
My model has a ForeignKey that renders as a SELECT field in HTML. The problem is that there's an empty value ('-') that I would like to hide. I've tried adding 'null=False' and 'blank=False' to the ForeignKey but the empty value still appears. Any suggestions? 2B

Re: select choices

2007-10-16 Thread Doug Van Horn
On Oct 15, 3:11 pm, onno <[EMAIL PROTECTED]> wrote: > Arn't stings slower against integers? A datatype of varchar versus integer isn't what's going to slow you down. If you don't have an index on a column and you use that column in your predicate (i.e., where clause) you will end up doing a

Re: select choices

2007-10-16 Thread Thomas Guettler
Am Montag, 15. Oktober 2007 22:11 schrieb onno: > Arn't stings slower against integers? Optimize later. You never know the bottleneck in advance. Thomas --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django

Re: select choices

2007-10-15 Thread RajeshD
> > Arn't stings slower against integers? You can always set db_index=True on the type field if you'll be using it a lot in your lookups and if the number of records in that table is going to be huge. http://www.djangoproject.com/documentation/model-api/#db-index

Re: select choices

2007-10-15 Thread onno
On Oct 15, 9:39 pm, Doug Van Horn <[EMAIL PROTECTED]> wrote: > On Oct 15, 1:51 pm, onno <[EMAIL PROTECTED]> wrote: > > > The most annoying thing about using: > > > TYPE = (('1', 'foo'),('2', 'BAR')) > > type = models.IntegerField(choices=TYPE) > > > Is that you can't do this in your views when

Re: select choices

2007-10-15 Thread Doug Van Horn
On Oct 15, 1:51 pm, onno <[EMAIL PROTECTED]> wrote: > The most annoying thing about using: > > TYPE = (('1', 'foo'),('2', 'BAR')) > type = models.IntegerField(choices=TYPE) > > Is that you can't do this in your views when you need to select > something > > Foo.objects.filter(type='BAR') > > you

Re: select choices

2007-10-15 Thread RajeshD
> Does anybody know a more easy way? Any particular reason you have to have type as an IntegerField? If you had it as a CharField, you could do: TYPE = (('foo', 'foo'), ('BAR', 'BAR')) type = models.CharField(choices=TYPE) Foo.objects.filter(type='BAR') And, possibly add db_index=True to the

select choices

2007-10-15 Thread onno
The most annoying thing about using: TYPE = (('1', 'foo'),('2', 'BAR')) type = models.IntegerField(choices=TYPE) Is that you can't do this in your views when you need to select something Foo.objects.filter(type='BAR') you have to remember what number you gave it or make some "def" to handle