The way to sort a list of ModelField on Kay

The list of entities generated by ModelField is automatically sorted by key that every entity has internally as a primary key.

Using seq_query method, you can modify the sorting rule.

Sentence Structure is like followng:

form = BookForm()
sorting = Categories.gql("ORDER BY id DESC")
form.form_category.set_query(sorting)

This example sentence is based on the following models.py and forms.py;

# models.py
class Categories(db.Model):
  id = db.StringProperty()
  category = db.StringProperty()
 
  def __unicode__(self):
    return self.category
 
 
class Books(db.Model):
  id = db.StringProperty()
  book = db.StringProperty()
  category = db.ReferenceProperty(Categories)
class BooksForm(forms.Form):
  form_id = forms.TextField(label="Book ID")
  form_book = forms.TextField(label="Book Name")
  form_category = forms.ModelField(model=Categories, default=None, label="Category of Book")