Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
08b501e7
Kaydet (Commit)
08b501e7
authored
May 19, 2013
tarafından
leandrafinger
Kaydeden (comit)
Silvan Spross
May 19, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
add missing imports to the examples in the 'Forms'
üst
1d543949
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
83 additions
and
0 deletions
+83
-0
form-preview.txt
docs/ref/contrib/formtools/form-preview.txt
+1
-0
api.txt
docs/ref/forms/api.txt
+0
-0
fields.txt
docs/ref/forms/fields.txt
+8
-0
validation.txt
docs/ref/forms/validation.txt
+9
-0
widgets.txt
docs/ref/forms/widgets.txt
+3
-0
formsets.txt
docs/topics/forms/formsets.txt
+26
-0
media.txt
docs/topics/forms/media.txt
+5
-0
modelforms.txt
docs/topics/forms/modelforms.txt
+31
-0
No files found.
docs/ref/contrib/formtools/form-preview.txt
Dosyayı görüntüle @
08b501e7
...
...
@@ -53,6 +53,7 @@ How to use ``FormPreview``
overrides the ``done()`` method::
from django.contrib.formtools.preview import FormPreview
from django.http import HttpResponseRedirect
from myapp.models import SomeModel
class SomeModelFormPreview(FormPreview):
...
...
docs/ref/forms/api.txt
Dosyayı görüntüle @
08b501e7
This diff is collapsed.
Click to expand it.
docs/ref/forms/fields.txt
Dosyayı görüntüle @
08b501e7
...
...
@@ -48,6 +48,7 @@ By default, each ``Field`` class assumes the value is required, so if you pass
an empty value -- either ``None`` or the empty string (``""``) -- then
``clean()`` will raise a ``ValidationError`` exception::
>>> from django import forms
>>> f = forms.CharField()
>>> f.clean('foo')
u'foo'
...
...
@@ -107,6 +108,7 @@ behavior doesn't result in an adequate label.
Here's a full example ``Form`` that implements ``label`` for two of its fields.
We've specified ``auto_id=False`` to simplify the output::
>>> from django import forms
>>> class CommentForm(forms.Form):
... name = forms.CharField(label='Your name')
... url = forms.URLField(label='Your Web site', required=False)
...
...
@@ -130,6 +132,7 @@ To specify dynamic initial data, see the :attr:`Form.initial` parameter.
The use-case for this is when you want to display an "empty" form in which a
field is initialized to a particular value. For example::
>>> from django import forms
>>> class CommentForm(forms.Form):
... name = forms.CharField(initial='Your name')
... url = forms.URLField(initial='http://')
...
...
@@ -205,6 +208,7 @@ methods (e.g., ``as_ul()``).
Here's a full example ``Form`` that implements ``help_text`` for two of its
fields. We've specified ``auto_id=False`` to simplify the output::
>>> from django import forms
>>> class HelpTextContactForm(forms.Form):
... subject = forms.CharField(max_length=100, help_text='100 characters max.')
... message = forms.CharField()
...
...
@@ -236,6 +240,7 @@ The ``error_messages`` argument lets you override the default messages that the
field will raise. Pass in a dictionary with keys matching the error messages you
want to override. For example, here is the default error message::
>>> from django import forms
>>> generic = forms.CharField()
>>> generic.clean('')
Traceback (most recent call last):
...
...
@@ -853,6 +858,7 @@ Slightly complex built-in ``Field`` classes
The list of fields that should be used to validate the field's value (in
the order in which they are provided).
>>> from django.forms import ComboField
>>> f = ComboField(fields=[CharField(max_length=20), EmailField()])
>>> f.clean('test@example.com')
u'test@example.com'
...
...
@@ -1001,6 +1007,8 @@ objects (in the case of ``ModelMultipleChoiceField``) into the
object, and should return a string suitable for representing it. For
example::
from django.forms import ModelChoiceField
class MyModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj):
return "My Object #%i" % obj.id
...
...
docs/ref/forms/validation.txt
Dosyayı görüntüle @
08b501e7
...
...
@@ -183,6 +183,9 @@ the ``default_validators`` attribute.
Simple validators can be used to validate values inside the field, let's have
a look at Django's ``SlugField``::
from django.forms import CharField
from django.core import validators
class SlugField(CharField):
default_validators = [validators.validate_slug]
...
...
@@ -252,6 +255,8 @@ we want to make sure that the ``recipients`` field always contains the address
don't want to put it into the general ``MultiEmailField`` class. Instead, we
write a cleaning method that operates on the ``recipients`` field, like so::
from django import forms
class ContactForm(forms.Form):
# Everything as before.
...
...
...
@@ -289,6 +294,8 @@ common method is to display the error at the top of the form. To create such
an error, you can raise a ``ValidationError`` from the ``clean()`` method. For
example::
from django import forms
class ContactForm(forms.Form):
# Everything as before.
...
...
...
@@ -321,6 +328,8 @@ here and leaving it up to you and your designers to work out what works
effectively in your particular situation. Our new code (replacing the previous
sample) looks like this::
from django import forms
class ContactForm(forms.Form):
# Everything as before.
...
...
...
docs/ref/forms/widgets.txt
Dosyayı görüntüle @
08b501e7
...
...
@@ -201,6 +201,7 @@ foundation for custom widgets.
.. code-block:: python
>>> from django import forms
>>> name = forms.TextInput(attrs={'size': 10, 'title': 'Your name',})
>>> name.render('name', 'A name')
u'<input title="Your name" type="text" name="name" value="A name" size="10" />'
...
...
@@ -249,6 +250,8 @@ foundation for custom widgets.
:class:`~datetime.datetime` value into a list with date and time split
into two separate values::
from django.forms import MultiWidget
class SplitDateTimeWidget(MultiWidget):
# ...
...
...
docs/topics/forms/formsets.txt
Dosyayı görüntüle @
08b501e7
...
...
@@ -56,6 +56,9 @@ telling the formset how many additional forms to show in addition to the
number of forms it generates from the initial data. Lets take a look at an
example::
>>> import datetime
>>> from django.forms.formsets import formset_factory
>>> from myapp.forms imporrt ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, extra=2)
>>> formset = ArticleFormSet(initial=[
... {'title': u'Django is now open source',
...
...
@@ -88,6 +91,8 @@ The ``max_num`` parameter to :func:`~django.forms.formsets.formset_factory`
gives you the ability to limit the maximum number of empty forms the formset
will display::
>>> from django.forms.formsets import formset_factory
>>> from myapp.forms imporrt ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, extra=2, max_num=1)
>>> formset = ArticleFormSet()
>>> for form in formset:
...
...
@@ -124,6 +129,8 @@ Validation with a formset is almost identical to a regular ``Form``. There is
an ``is_valid`` method on the formset to provide a convenient way to validate
all forms in the formset::
>>> from django.forms.formsets import formset_factory
>>> from myapp.forms imporrt ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm)
>>> data = {
... 'form-TOTAL_FORMS': u'1',
...
...
@@ -230,6 +237,8 @@ A formset has a ``clean`` method similar to the one on a ``Form`` class. This
is where you define your own validation that works at the formset level::
>>> from django.forms.formsets import BaseFormSet
>>> from django.forms.formsets import formset_factory
>>> from myapp.forms import ArticleForm
>>> class BaseArticleFormSet(BaseFormSet):
... def clean(self):
...
...
@@ -276,6 +285,8 @@ If ``validate_max=True`` is passed to
:func:`~django.forms.formsets.formset_factory`, validation will also check
that the number of forms in the data set is less than or equal to ``max_num``.
>>> from django.forms.formsets import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, max_num=1, validate_max=True)
>>> data = {
... 'form-TOTAL_FORMS': u'2',
...
...
@@ -329,6 +340,8 @@ Default: ``False``
Lets you create a formset with the ability to order::
>>> from django.forms.formsets import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, can_order=True)
>>> formset = ArticleFormSet(initial=[
... {'title': u'Article #1', 'pub_date': datetime.date(2008, 5, 10)},
...
...
@@ -385,6 +398,8 @@ Default: ``False``
Lets you create a formset with the ability to delete::
>>> from django.forms.formsets import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, can_delete=True)
>>> formset = ArticleFormSet(initial=[
... {'title': u'Article #1', 'pub_date': datetime.date(2008, 5, 10)},
...
...
@@ -437,6 +452,9 @@ accomplished. The formset base class provides an ``add_fields`` method. You
can simply override this method to add your own fields or even redefine the
default fields/attributes of the order and deletion fields::
>>> from django.forms.formsets import BaseFormSet
>>> from django.forms.formsets import formset_factory
>>> from myapp.forms import ArticleForm
>>> class BaseArticleFormSet(BaseFormSet):
... def add_fields(self, form, index):
... super(BaseArticleFormSet, self).add_fields(form, index)
...
...
@@ -459,6 +477,10 @@ management form inside the template. Let's look at a sample view:
.. code-block:: python
from django.forms.formsets import formset_factory
from django.shortcuts import render_to_response
from myapp.forms import ArticleForm
def manage_articles(request):
ArticleFormSet = formset_factory(ArticleForm)
if request.method == 'POST':
...
...
@@ -534,6 +556,10 @@ a look at how this might be accomplished:
.. code-block:: python
from django.forms.formsets import formset_factory
from django.shortcuts import render_to_response
from myapp.forms import ArticleForm, BookForm
def manage_articles(request):
ArticleFormSet = formset_factory(ArticleForm)
BookFormSet = formset_factory(BookForm)
...
...
docs/topics/forms/media.txt
Dosyayı görüntüle @
08b501e7
...
...
@@ -49,6 +49,8 @@ define the media requirements.
Here's a simple example::
from django import froms
class CalendarWidget(forms.TextInput):
class Media:
css = {
...
...
@@ -211,6 +213,7 @@ to using :setting:`MEDIA_URL`. For example, if the :setting:`MEDIA_URL` for
your site was ``'http://uploads.example.com/'`` and :setting:`STATIC_URL`
was ``None``::
>>> from django import forms
>>> class CalendarWidget(forms.TextInput):
... class Media:
... css = {
...
...
@@ -267,6 +270,7 @@ Combining media objects
Media objects can also be added together. When two media objects are added,
the resulting Media object contains the union of the media from both files::
>>> from django import forms
>>> class CalendarWidget(forms.TextInput):
... class Media:
... css = {
...
...
@@ -298,6 +302,7 @@ Regardless of whether you define a media declaration, *all* Form objects
have a media property. The default value for this property is the result
of adding the media definitions for all widgets that are part of the form::
>>> from django import forms
>>> class ContactForm(forms.Form):
... date = DateField(widget=CalendarWidget)
... name = CharField(max_length=40, widget=OtherWidget)
...
...
docs/topics/forms/modelforms.txt
Dosyayı görüntüle @
08b501e7
...
...
@@ -23,6 +23,7 @@ class from a Django model.
For example::
>>> from django.forms import ModelForm
>>> from myapp.models import Article
# Create the form class.
>>> class ArticleForm(ModelForm):
...
...
@@ -222,6 +223,9 @@ supplied, ``save()`` will update that instance. If it's not supplied,
.. code-block:: python
>>> from myapp.models import Article
>>> from myapp.forms import ArticleForm
# Create a form instance from POST data.
>>> f = ArticleForm(request.POST)
...
...
@@ -316,6 +320,8 @@ these security concerns do not apply to you:
1. Set the ``fields`` attribute to the special value ``'__all__'`` to indicate
that all fields in the model should be used. For example::
from django.forms import ModelForm
class AuthorForm(ModelForm):
class Meta:
model = Author
...
...
@@ -401,6 +407,7 @@ of its default ``<input type="text">``, you can override the field's
widget::
from django.forms import ModelForm, Textarea
from myapp.models import Author
class AuthorForm(ModelForm):
class Meta:
...
...
@@ -421,6 +428,9 @@ you can do this by declaratively specifying fields like you would in a regular
For example, if you wanted to use ``MyDateFormField`` for the ``pub_date``
field, you could do the following::
from django.forms import ModelForm
from myapp.models import Article
class ArticleForm(ModelForm):
pub_date = MyDateFormField()
...
...
@@ -432,6 +442,9 @@ field, you could do the following::
If you want to override a field's default label, then specify the ``label``
parameter when declaring the form field::
from django.forms import ModelForm, DateField
from myapp.models import Article
class ArticleForm(ModelForm):
pub_date = DateField(label='Publication date')
...
...
@@ -484,6 +497,8 @@ By default, the fields in a ``ModelForm`` will not localize their data. To
enable localization for fields, you can use the ``localized_fields``
attribute on the ``Meta`` class.
>>> from django.forms import ModelForm
>>> from myapp.models import Author
>>> class AuthorForm(ModelForm):
... class Meta:
... model = Author
...
...
@@ -574,6 +589,7 @@ definition. This may be more convenient if you do not have many customizations
to make::
>>> from django.forms.models import modelform_factory
>>> from myapp.models import Book
>>> BookForm = modelform_factory(Book, fields=("author", "title"))
This can also be used to make simple modifications to existing forms, for
...
...
@@ -604,6 +620,7 @@ of enhanced formset classes that make it easy to work with Django models. Let's
reuse the ``Author`` model from above::
>>> from django.forms.models import modelformset_factory
>>> from myapp.models import Author
>>> AuthorFormSet = modelformset_factory(Author)
This will create a formset that is capable of working with the data associated
...
...
@@ -642,6 +659,7 @@ Alternatively, you can create a subclass that sets ``self.queryset`` in
``__init__``::
from django.forms.models import BaseModelFormSet
from myapp.models import Author
class BaseAuthorFormSet(BaseModelFormSet):
def __init__(self, *args, **kwargs):
...
...
@@ -787,6 +805,10 @@ Using a model formset in a view
Model formsets are very similar to formsets. Let's say we want to present a
formset to edit ``Author`` model instances::
from django.forms.models import modelformset_factory
from django.shortcuts import render_to_response
from myapp.models import Author
def manage_authors(request):
AuthorFormSet = modelformset_factory(Author)
if request.method == 'POST':
...
...
@@ -815,12 +837,15 @@ the unique constraints on your model (either ``unique``, ``unique_together`` or
on a ``model_formset`` and maintain this validation, you must call the parent
class's ``clean`` method::
from django.forms.models import BaseModelFormSet
class MyModelFormSet(BaseModelFormSet):
def clean(self):
super(MyModelFormSet, self).clean()
# example custom validation across forms in the formset:
for form in self.forms:
# your custom formset validation
pass
Using a custom queryset
-----------------------
...
...
@@ -828,6 +853,10 @@ Using a custom queryset
As stated earlier, you can override the default queryset used by the model
formset::
from django.forms.models import modelformset_factory
from django.shortcuts import render_to_response
from myapp.models import Author
def manage_authors(request):
AuthorFormSet = modelformset_factory(Author)
if request.method == "POST":
...
...
@@ -914,6 +943,8 @@ Inline formsets is a small abstraction layer on top of model formsets. These
simplify the case of working with related objects via a foreign key. Suppose
you have these two models::
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment