Package couchdbkit :: Package ext :: Package django :: Module forms
[hide private]
[frames] | no frames]

Module forms

source code

Implement DocumentForm object. It map Document objects to Form and 
works like ModelForm object :

    >>> from couchdbkit.ext.django.forms  import DocumentForm

    # Create the form class.
    >>> class ArticleForm(DocumentForm):
    ...     class Meta:
    ...         model = Article

    # Creating a form to add an article.
    >>> form = ArticleForm()

    # Creating a form to change an existing article.
    >>> article = Article.get(someid)
    >>> form = ArticleForm(instance=article)
    

The generated Form class will have a form field for every model field. 
Each document property has a corresponding default form field:

* StringProperty   ->  CharField,
* IntegerProperty  ->  IntegerField,
* DecimalProperty  ->  DecimalField,
* BooleanProperty  ->  BooleanField,
* FloatProperty    ->  FloatField,
* DateTimeProperty ->  DateTimeField,
* DateProperty     ->  DateField,
* TimeProperty     ->  TimeField


More fields types will be supported soon.

Classes [hide private]
  DocumentFormOptions
  DocumentFormMetaClass
  BaseDocumentForm
Base Document Form object
  DocumentForm
The document form object
Functions [hide private]
 
document_to_dict(instance, properties=None, exclude=None)
Returns a dict containing the data in ``instance`` suitable for passing as a Form's ``initial`` keyword argument.
source code
 
fields_for_document(document, properties=None, exclude=None)
Returns a ``SortedDict`` containing form fields for the given document.
source code
Variables [hide private]
  FIELDS_PROPERTES_MAPPING = {'BooleanProperty': <class 'django....
  __package__ = 'couchdbkit.ext.django'
Function Details [hide private]

document_to_dict(instance, properties=None, exclude=None)

source code 

Returns a dict containing the data in ``instance`` suitable for passing as a Form's ``initial`` keyword argument.

``properties`` is an optional list of properties names. If provided, only the named properties will be included in the returned dict.

``exclude`` is an optional list of properties names. If provided, the named properties will be excluded from the returned dict, even if they are listed in the ``properties`` argument.

fields_for_document(document, properties=None, exclude=None)

source code 

Returns a ``SortedDict`` containing form fields for the given document.

``properties`` is an optional list of properties names. If provided, only the named properties will be included in the returned properties.

``exclude`` is an optional list of properties names. If provided, the named properties will be excluded from the returned properties, even if they are listed in the ``properties`` argument.


Variables Details [hide private]

FIELDS_PROPERTES_MAPPING

Value:
{'BooleanProperty': <class 'django.forms.fields.BooleanField'>,
 'DateProperty': <class 'django.forms.fields.DateField'>,
 'DateTimeProperty': <class 'django.forms.fields.DateTimeField'>,
 'DecimalProperty': <class 'django.forms.fields.DecimalField'>,
 'FloatProperty': <class 'django.forms.fields.FloatField'>,
 'IntegerProperty': <class 'django.forms.fields.IntegerField'>,
 'StringProperty': <class 'django.forms.fields.CharField'>,
 'TimeProperty': <class 'django.forms.fields.TimeField'>}