views:

28

answers:

1

Wanted effect is passing the id to the request handler and populating the form with that entity. How doable is it with a template? Here are my form, request handler and template

class AForm(djangoforms.ModelForm):  
  text = forms.CharField(widget=forms.Textarea(attrs={'rows':'11','cols':'70','class':'foo'}),label=_("content").capitalize())
  class Meta:
        model = A
        fields = ['category','currency','price','title','phonenumber','postaladress','name','text','email'] #change the order


class FileUploadFormHandler(I18NHandler):
  def get(self):
    cookie_django_language = self.request.get('hl', '') 
    if cookie_django_language:
      if cookie_django_language == 'unset':
        del self.request.COOKIES['django_language']
      else:
        self.request.COOKIES['django_language'] = cookie_django_language
        translation.activate(cookie_django_language)   
    self.render_template("upload.html", {
        'form': AForm(),
        'form_url': blobstore.create_upload_url('/fileupload'),
        'logout_url': users.create_logout_url('/'),
    })


 <table>
{% for field in form %}
<tr><td>
    <div class="fieldWrapper">
        {{ form.title.errors }}
        <label for="id_subject">{% filter capfirst %}{% trans "headline" %}{% endfilter %}</label></td><td>
        {{ form.title }}</td></tr>
    </div><tr><td>
    <div class="fieldWrapper">
        {{ form.category.errors }}
        <label for="id_subject">{% filter capfirst %}{% trans "content" %}{% endfilter %}</label></td><td>
+3  A: 

You should initialize your form with the entity you want to show:

form = AForm(instance = some_model_instance)
Eran Kampf
Thank you. It works.
LarsOn