I probably need to be more specific..

here's my model:

class Recipe(modesl.Model):

   recipetitle = models.CharField()
   cooking_method = models.ForeignKey(CookingMethod)

class CookingMethod(models.Model):

   cookmethodname = models.CharField()


forms.py

  class RecipeForm(forms.Form):

        title = forms.CharField()
        cookmethod =
forms.ModelChoiceField(queryset=CookingMethod.objects.all())

views.py

   def edit_recipe(request,recipe_id):

     if request.method == "POST":
        yadda yadda

    else:
           recipe = Recipe.objects.get(id=recipe_id)
           recipeform = RecipeForm()
           recipeform.fields['title'] = recipe.recipetitle
           recipeform.fields['cooking_method'] = recipe.cooking_method


When a new recipe is created, all the different cooking methods
correctly show up in the recipe form as a <Select> html element
(corresponding to the ModelChoice field in the form).

However, when an existing recipe is being edited, the recipe title is
retrieved correctly, but the corresponding recipe cooking method is
not displayed in the <select> html element. instead, the one
corresponding to the empty label (------) shows up.

Any ideas ? I'm losing my mind over this.

thanks in advance.


On Jun 22, 11:15 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> In a form, I have a field defined asModelChoiceField
>
> class myForm(forms.Form)
>   myfield = forms.ModelChoiceField(MyClass.objects.all())
>  myfield2 = forms.CharField()
>
> My problem is that I cant seem to dynamically set the value that the
> user selected for this field. When ever, user edits the record, this
> select list always gets set to no value instead of the value that the
> user had originally selected.
>
> the input text field has no problems in showing the saved data
> correctly.
>
> am I missing something ?
>
> thnx,
> -p
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to