R – How to modify attributes of forms generated by webapp (Google App Engine)


Here are model and form classes from example:


class Item(db.Model):
  name = db.StringProperty()
  quantity = db.IntegerProperty(default=1)
  target_price = db.FloatProperty()
  priority = db.StringProperty(default='Medium',choices=[
    'High', 'Medium', 'Low'])
  entry_time = db.DateTimeProperty(auto_now_add=True)
  added_by = db.UserProperty()

class ItemForm(djangoforms.ModelForm):
  class Meta:
    model = Item
    exclude = ['added_by']

It will be rendered as table rows.

Can I change how they will be rendered (change width or make it to be list instead of table row or anything…)?

Best Solution

Take a look at the Django forms docs, here. The docs are for 1.0, but most of it applies to the 0.91 version bundled with App Engine, too.

The short answer to your question: form.as_p will generate an HTML representation of the form as a series of <p> tags, while form.as_ul will generate a series of <ul> tags and form.as_table will generate a table.