Thursday, June 30, 2011

Drop down box in django getting populated from a database table column

I searched the same thing on net and got many answers but some how
dint get working with any of them. Table: 1. Report :
reportType(foreign key from ReportCategory), name, description 2.
Report Category: name,description

class ReportForm_insert(forms.ModelForm):

class Meta:
invent = ReportCategory.objects.all()
print invent
reportType_id = forms.ModelMultipleChoiceField(queryset = invent)

fields =('name','description',)

class ReportCategory(models.Model):

name = models.CharField(max_length=20)

description = models.CharField(max_length=20)

def __unicode__(self):

class Report(models.Model):

reportType = models.CharField(max_length=200)

name = models.CharField(max_length=200)

description = models.CharField(max_length=300)

def __unicode__(self):

I want the ReportType to be shown as a drop down box which would
contain values from the name column of the Report Category table. I am
surely going wrong big way but I am not understanding what to do... So
I am not understanding whether there is a problem with not able to
handle the foreign key or the drop down box.

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment