Skip to content

Commit

Permalink
in demos use less docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Jan 21, 2024
1 parent 4cf82c5 commit 5ae3978
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions testapp/forms/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,8 @@

class ArticleForm(forms.Form):
"""
Using a ``SlugField``
---------------------
In Django's Admin, a ``SlugField`` can be configured to be prepopulated using the content of
another text input field. To emulate a similar behaviour, **django-formset** provides a special
widget named ``SlugInput``.
.. code-block:: python
from django.forms import fields, forms
class ArticleForm(...):
...
title = fields.CharField(
label="Title",
max_length=100,
)
slug = fields.SlugField(
label="Slug",
widget=SlugInput('title'),
)
...
This widget takes a single attribute with the name of another field of the same form.
That field's input value then is used to prepopulate the slug field, where the generated value
is produced by concatenating the values of the source fields, and then by transforming that
result into a valid slug (e.g. substituting dashes for spaces, lowercasing letters and rewriting
unicode characters to ASCII letters).
Prefilled slug fields aren't modified after a value has been saved as this usually is undesired
behaviour.
In Django, a ``SlugField`` can be configured to be prepopulated using the content of another text input
field. To emulate a similar behaviour, **django-formset** provides a special widget named ``SlugInput``.
"""

title = fields.CharField(
Expand All @@ -47,4 +17,5 @@ class ArticleForm(...):
slug = fields.SlugField(
label="Slug",
widget=SlugInput('title'),
help_text="The slug will be automatically generated from the title",
)

0 comments on commit 5ae3978

Please sign in to comment.