• Stars
    star
    110
  • Rank 306,507 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 12 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WTForms integration for peewee

wtf-peewee

this project, based on the code found in wtforms.ext, provides a bridge between peewee models and wtforms, mapping model fields to form fields.

example usage:

first, create a couple basic models and then use the model_form class factory to create a form for the Entry model:

from peewee import *
from wtfpeewee.orm import model_form
import wtforms

class PasswordField(TextField):
    """ Custom-defined field example. """
    def wtf_field(self, model, **kwargs):
        return wtforms.PasswordField(**kwargs)

class Blog(Model):
    name = CharField()

    def __unicode__(self):
        return self.name

class Entry(Model):
    blog = ForeignKeyField(Blog)
    title = CharField()
    body = TextField()
    protected = PasswordField()

    def __unicode__(self):
        return self.title

# create a form class for use with the Entry model
EntryForm = model_form(Entry)

Example implementation for an "edit" view using Flask:

@app.route('/entries/<int:entry_id>/', methods=['GET', 'POST'])
def edit_entry(entry_id):
    try:
        entry = Entry.get(id=entry_id)
    except Entry.DoesNotExist:
        abort(404)

    if request.method == 'POST':
        form = EntryForm(request.form, obj=entry)
        if form.validate():
            form.populate_obj(entry)
            entry.save()
            flash('Your entry has been saved')
    else:
        form = EntryForm(obj=entry)

    return render_template('blog/entry_edit.html', form=form, entry=entry)

Example template for above view:

{% extends "layout.html" %}
{% block body %}
  <h2>Edit {{ entry.title }}</h2>

  <form method="post" action="">
    {% for field in form %}
      <p>{{ field.label }} {{ field }}</p>
    {% endfor %}
    <p><button type="submit">Submit</button></p>
  </form>
{% endblock %}

More Repositories

1

peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
Python
10,766
star
2

huey

a little task queue for python
Python
4,869
star
3

sqlite-web

Web-based SQLite database browser written in Python
Python
2,867
star
4

walrus

Lightweight Python utilities for working with Redis
Python
1,135
star
5

flask-peewee

flask integration for peewee, including admin, authentication, rest api and more
Python
770
star
6

micawber

a small library for extracting rich content from urls
Python
621
star
7

unqlite-python

Python bindings for the UnQLite embedded NoSQL database
C
387
star
8

django-relationships

Descriptive relationships between auth.users (think facebook friends and twitter followers, plus more)
Python
367
star
9

scout

RESTful search server written in Python, powered by SQLite.
Python
294
star
10

irc

tinkering with a made-from-scratch irc library in python
Python
181
star
11

pysqlite3

SQLite3 DB-API 2.0 driver from Python 3, packaged separately, with improvements
C
159
star
12

django-generic-m2m

relate anything to anything
Python
151
star
13

simpledb

miniature redis-like server implemented in Python
Python
137
star
14

python-lsm-db

Python bindings for the SQLite4 LSM database.
C
129
star
15

vedis-python

Python bindings for the Vedis embedded NoSQL database
C
122
star
16

sophy

Fast Python bindings to Sophia Database
C
80
star
17

sqlcipher3

Python 3 bindings for SQLCipher
C
75
star
18

django-generic-aggregation

annotate() and aggregate() for generically-related data.
Python
72
star
19

ucache

gametight lightweight caching library for python
Python
65
star
20

beefish

simple file encryption with pycrypto
Python
65
star
21

chrome-extensions

Personal collection of chrome extensions
JavaScript
61
star
22

sqlite-vtfunc

Implement SQLite table-valued functions with Python
Cython
56
star
23

sweepea

Fast, lightweight Python database toolkit for SQLite, built with Cython.
Cython
41
star
24

dot-theme

dotfile templating tools
Python
31
star
25

greendb

server frontend for lmdb
Python
24
star
26

kvkit

dank key/value store high-level APIs
Python
18
star
27

kt

Fast Python client for KyotoTycoon
Python
17
star
28

ukt

Kyoto Tycoon client library for Python.
Python
11
star
29

sqlite3-bloomfilter

Bloomfilter for SQLite3
C
6
star