Re: How To Populate A Dropdown List

2011-02-09 Thread Malcolm MacKinnon
And one more file to render the drop down list, order_closeouts.html below.
Sorry about the messy code. It ain't pretty but it works for me. Let me know
if you have any questions.

I forgot to initialize the form in my view. See views.py below.

Here's some sample code that works for me:

in models.py
class InventoryCloseouts(models.Model):
   prim = models.IntegerField(primary_key=True, db_column='PRIM') #
Field name made lowercase.
   items = models.CharField(max_length=255, db_column='ITEMS',
blank=True) # Field name made lowe
   gen = models.CharField(max_length=255, db_column='GEN',
blank=True) # Field name made lowercase.
   descrip = models.CharField(max_length=255, db_column='DESCRIP',
blank=True) # Field name made l
 .. etc.
   def __unicode__(self):
return self.items + ":" + self.gen+":"+self.descrip

in forms.py
class InvtForm2(forms.Form):   #used in closeout order view.
   invent=InventoryCloseouts.objects.all()
   items = forms.ModelMultipleChoiceField(queryset=invent,
 widget=forms.Select(attrs={'class':'colr', }))

in views.py
def order_closeouts(request):
forms=InvtForm2()
  etc.

return render_to_response('order_closeouts.html', {'forms':forms},
   context_instance = RequestContext(request))

in order_closeouts.html

{{forms.items}}<--Select Item from complete
list

On Wed, Feb 9, 2011 at 9:58 PM, Malcolm MacKinnon wrote:

>
>
> On Wed, Feb 9, 2011 at 9:54 PM, Mac  wrote:
>
>>
>>
>> On Feb 8, 8:03 am, hank23  wrote:
>> > I have coded a form which will display some data in a dropdown
>> > selection box. The data is being populated from a a queryset that I
>> > have setup in the form's code. However the entries in the dropdown
>> > only display as objects of the table from which they're being
>> > retrieved, and don't display the actual field data that I was hoping
>> > to have it display. So how do I specify in the form which of the table
>> > fields is to be the display field and which is suppoed to be the
>> > underying key value to be passed when and entry is selected? Thanks
>> > for the help.
>>
>> --
>> 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.



Re: How To Populate A Dropdown List

2011-02-09 Thread Malcolm MacKinnon
I forgot to initialize the form in my view. See views.py below.

Here's some sample code that works for me:

in models.py
class InventoryCloseouts(models.Model):
   prim = models.IntegerField(primary_key=True, db_column='PRIM') #
Field name made lowercase.
   items = models.CharField(max_length=255, db_column='ITEMS',
blank=True) # Field name made lowe
   gen = models.CharField(max_length=255, db_column='GEN',
blank=True) # Field name made lowercase.
   descrip = models.CharField(max_length=255, db_column='DESCRIP',
blank=True) # Field name made l
 .. etc.
   def __unicode__(self):
return self.items + ":" + self.gen+":"+self.descrip

in forms.py
class InvtForm2(forms.Form):   #used in closeout order view.
   invent=InventoryCloseouts.objects.all()
   items = forms.ModelMultipleChoiceField(queryset=invent,
 widget=forms.Select(attrs={'class':'colr', }))

in views.py
def order_closeouts(request):
forms=InvtForm2()
  etc.
return render_to_response('order_closeouts.html', {'forms':forms},
   context_instance = RequestContext(request))

On Wed, Feb 9, 2011 at 9:54 PM, Mac  wrote:

>
>
> On Feb 8, 8:03 am, hank23  wrote:
> > I have coded a form which will display some data in a dropdown
> > selection box. The data is being populated from a a queryset that I
> > have setup in the form's code. However the entries in the dropdown
> > only display as objects of the table from which they're being
> > retrieved, and don't display the actual field data that I was hoping
> > to have it display. So how do I specify in the form which of the table
> > fields is to be the display field and which is suppoed to be the
> > underying key value to be passed when and entry is selected? Thanks
> > for the help.
>
> --
> 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.



Re: How To Populate A Dropdown List

2011-02-09 Thread Mac
Here's some sample code that works for me:

in models.py
class InventoryCloseouts(models.Model):
prim = models.IntegerField(primary_key=True, db_column='PRIM') #
Field name made lowercase.
items = models.CharField(max_length=255, db_column='ITEMS',
blank=True) # Field name made lowe
gen = models.CharField(max_length=255, db_column='GEN',
blank=True) # Field name made lowercase.
descrip = models.CharField(max_length=255, db_column='DESCRIP',
blank=True) # Field name made l
  .. etc.
def __unicode__(self):
 return self.items + ":" + self.gen+":"+self.descrip

in forms.py
class InvtForm2(forms.Form):   #used in closeout order view.
invent=InventoryCloseouts.objects.all()
items = forms.ModelMultipleChoiceField(queryset=invent,
widget=forms.Select(attrs={'class':'colr', }))

in views.py
def order_closeouts(request):


return render_to_response('order_closeouts.html', {'forms':forms},
context_instance = RequestContext(request))

On Feb 8, 8:03 am, hank23  wrote:
> I have coded a form which will display some data in a dropdown
> selection box. The data is being populated from a a queryset that I
> have setup in the form's code. However the entries in the dropdown
> only display as objects of the table from which they're being
> retrieved, and don't display the actual field data that I was hoping
> to have it display. So how do I specify in the form which of the table
> fields is to be the display field and which is suppoed to be the
> underying key value to be passed when and entry is selected? Thanks
> for the help.

-- 
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.



Re: How To Populate A Dropdown List

2011-02-09 Thread SimpleDimple
did it work Hank ?

On Feb 9, 7:47 am, Brian Neal  wrote:
> On Feb 8, 10:03 am, hank23  wrote:
>
> > I have coded a form which will display some data in a dropdown
> > selection box. The data is being populated from a a queryset that I
> > have setup in the form's code. However the entries in the dropdown
> > only display as objects of the table from which they're being
> > retrieved, and don't display the actual field data that I was hoping
> > to have it display. So how do I specify in the form which of the table
> > fields is to be the display field and which is suppoed to be the
> > underying key value to be passed when and entry is selected? Thanks
> > for the help.
>
> Post your code somewhere, e.g. dpaste.com so we have a better idea
> what you are trying to do.
>
> Best,
> BN

-- 
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.



Re: How To Populate A Dropdown List

2011-02-08 Thread Brian Neal
On Feb 8, 10:03 am, hank23  wrote:
> I have coded a form which will display some data in a dropdown
> selection box. The data is being populated from a a queryset that I
> have setup in the form's code. However the entries in the dropdown
> only display as objects of the table from which they're being
> retrieved, and don't display the actual field data that I was hoping
> to have it display. So how do I specify in the form which of the table
> fields is to be the display field and which is suppoed to be the
> underying key value to be passed when and entry is selected? Thanks
> for the help.

Post your code somewhere, e.g. dpaste.com so we have a better idea
what you are trying to do.

Best,
BN

-- 
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.



Re: How To Populate A Dropdown List

2011-02-08 Thread SimpleDimple
I am new to django so not sure if I am of much help but let me try

the key is usually the ID field of your table.
for the value to display add a method __str___ in your model, here is
sample code from one of my project
read more on ___str___ and ___unicode___ methods


class Teacher(models.Model):
school= models.ForeignKey("School")
xclass= models.ForeignKey("Class", verbose_name='Class')
name  = models.CharField("Teacher Name",max_length=50)

def __str__(self):
   return self.name


On Feb 8, 9:03 pm, hank23  wrote:
> I have coded a form which will display some data in a dropdown
> selection box. The data is being populated from a a queryset that I
> have setup in the form's code. However the entries in the dropdown
> only display as objects of the table from which they're being
> retrieved, and don't display the actual field data that I was hoping
> to have it display. So how do I specify in the form which of the table
> fields is to be the display field and which is suppoed to be the
> underying key value to be passed when and entry is selected? Thanks
> for the help.

-- 
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.