On Feb 20, 9:52 pm, Mario Gudelj <mario.gud...@gmail.com> wrote:
> Hey there,
>
> Try this:
>
> In your forms.py create a field such as this
>
> message = forms.ChoiceField(label='Event Type', choices=EVENT_TYPE_CHOICES)
>
> That will create a dropdown.

My app does not have a forms.py file. I know I can just create one,
but then how would that field be scoped? I want it to be part of the
EventsTable class.


> Also, I think that the first thing in the tuple is a value and shouldn't
> have a space, so change:
>
> EVENT_TYPE_CHOICES = (('Event Created', 'EventCreated'),('Event Changed',
> 'EventChanged'),)
>
> to:
>
> EVENT_TYPE_CHOICES = (('event_created', 'Event Created'),('event_changed',
> 'Event Changed'),)
>
> See if that works for you.

Changing that did not have any effect.


>
> Cheers,
>
> -m
>
>  message = models.CharField("Event Type", max_length=12,
>
> > > choices=EVENT_TYPE_CHOICES)
>
> On 21 February 2012 12:28, larry.mart...@gmail.com
> <larry.mart...@gmail.com>wrote:
>
>
>
>
>
>
>
> > On Feb 20, 5:54 pm, Anurag Chourasia <anurag.choura...@gmail.com>
> > wrote:
> > > This is weird....
>
> > > I simply copy pasted your code in my environment and it shows me a Drop
> > > Down.
>
> > > Could you save the models file again and close your browser (or even try
> > > clearing cache) and restart your apache/django dev server whatever may be
> > > the case and try again?
>
> > Tried all that, still no joy. Also tried 2 different browsers, no
> > difference. In the dev server also tried setting a breakpoint and then
> > printing out message.choices, and it has the choices I expected:
>
> > (Pdb) print message.choices
> > (('Event Created', 'EventCreated'), ('Event Changed', 'EventChanged'))
>
> > > Regards,
> > > Anurag
>
> > > On Mon, Feb 20, 2012 at 9:32 PM, larry.mart...@gmail.com <
>
> > > larry.mart...@gmail.com> wrote:
> > > > I'm fairly new to django, still getting my feet wet. I want to have a
> > > > dropdown menu (django seems to call this a select box). I read this:
>
> > > >https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mo.
> > ..
>
> > > > So I did this:
>
> > > > class EventsTable(models.Model):
> > > >    EVENT_TYPE_CHOICES = (
> > > >        ('Event Created', 'EventCreated'),
> > > >        ('Event Changed', 'EventChanged'),
> > > >    )
>
> > > >    message = models.CharField("Event Type", max_length=12,
> > > > choices=EVENT_TYPE_CHOICES)
>
> > > > But I get a standard text entry field where I can type in anything.
>
> > > > I did more googling, and I read a lot of confusing stuff about having
> > > > to use javascrpt, ajax, CSS, etc. I read some pages about using a
> > > > ChoiceField, but that is not part of the model class (it's in the
> > > > forms class). I'm not sure how that would be used with a class that
> > > > inherits form models.
>
> > > > What am I missing here? I can't imagine something as common as this
> > > > would be hard in django. Shouldn't the first thing I did work?
>
> > > > TIA!
> > > > -larry
>
> > > > --
> > > > 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
> > > > django-users+unsubscr...@googlegroups.com.
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/django-users?hl=en.
>
> > --
> > 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
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to