I have created a bounded ModelChoiceField like this :
Model:
----------
class Project(models.Model):
name = models.CharField()
class Staff(models.Model):
name = models.CharField()
project = models.ForeignKey(Project)
Forms:
----------
class StaffForm(newforms.Form):
name = forms.CharField()
project = models.ModelChoiceField(Project.objects.all())
Views:
---------
def StaffView(request):
.....
staff = Staff.objects.get(pk=1) # assume this record exist in the
db
data = {'name':staff.name , 'project':staff.project}
form = StaffForm(data) # a bounded form
return render_to_response('template.html', {'form':form})
But I can not set selected="selected" in <option></option> in the View
output. I know that I can use unbounded form and initial parameter but
I guess I need bounded Form in my scenario. I tried many different
things with no success to show current project in the selection box of
StaffForm.project. I am suspicious that django by design, do not want
me to use bounded Form to initiate ChoiceField / ModelChoiceField in
the view or may be I am wrong. But I use it many times in admin site
using many to many and many to one relations but I could not simulate
it myself yet.
I would appreciate any help regarding this issue.
With Regards.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---