Without seeing your model or your data, it's hard to tell what's going
on.

You're overriding the queryset for those two fields. If the instance's
values for those two fields is not in that updated queryset, then your
widgets won't get a default value.

In other words, if the value of "b_name" for the instance is 1 and the
queryset is limited to values 2,3,4 and 5, then you won't see a
default value.

On Jun 5, 6:06 am, sushanth Reddy <sushant...@gmail.com> wrote:
> Hi,
>
> When i edit a records  none of the modelchoicefields are getting selected
> using form edit form instance.
>
> I have gone though below blog, but confusing
>
> http://blog.brendel.com/2009/07/setting-initial-value-for-djangos.html
>
> *view.py* :
>
> def EditTable(request, get_id):
>   detail_data = shortcuts.get_object_or_404(models.TestTable, id=get_id)
>   if request.method == 'POST':
>     form = forms.EditForm(
>         request, data=request.POST, instance=detail_data)
>     if form_is_valid():
>         form.save()
>   else:
>     form  =  forms.EditForm(instance=detail_data)
>  return form
>
> *form.py*
>
> class EditForm(forms.ModelForm):
>   activity = forms.TypedChoiceField(choices=choice.Activity_CHOICES)
>   def __init__(self,  *args, **kwargs):
>     super(EditForm, self).__init__(*args, **kwargs)
>     self.fields['b_name'] = forms.ModelChoiceField(
>         queryset=models.CreateDb.objects.filter( list_p='English',
> status='A'),
>     self.fields['type'] = forms.ModelChoiceField(
>         queryset=models.CreateType.objects.filter( list_T='Grammer',
> status='A'),
>
> I any help really appreciate.

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