Skip to content

Commit 74e7fc3

Browse files
authored
Update README.md
1 parent 6931136 commit 74e7fc3

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

README.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ Requirements: `django>=2.*`
4141
`pip install django-streamfield`
4242

4343
## How to use
44+
- Create streamblocks app with your models
45+
- Add streamfield and streamblocks to INSTALLED_APPS
46+
- Add streamfield.urls
47+
- Create templates for streamblocks
48+
- Add StreamField to your model
49+
- Use it in templates
4450

45-
**1. Create new app called `streamblocks`**
46-
Here will be your models that you will use as blocks
51+
**1. Create new app called `streamblocks` and put there some models**
4752

48-
**2. Put to `streamblocks/models.py` some models**
49-
50-
...that you want to use as blocks in your stream field.
53+
...that you want to use as blocks in your StreamField.
5154
Add them to the list `STREAMBLOCKS_MODELS`.
5255
For example:
5356

@@ -84,7 +87,7 @@ STREAMBLOCKS_MODELS = [
8487
> Important!: Don't use 'as_list', 'options', 'extra_options' as models field names, because they are used by streamfield.
8588
8689

87-
**3. Add apps to settings.py**
90+
**2. Add apps to settings.py**
8891

8992
Add to INSTALLED_APPS
9093

@@ -96,14 +99,14 @@ INSTALLED_APPS = [
9699
...
97100
```
98101

99-
**4. Add streamfield.urls to main urls.py**
102+
**3. Add streamfield.urls to main urls.py**
100103
```python
101104
urlpatterns += [
102105
path('streamfield/', include('streamfield.urls'))
103106
]
104107
```
105108

106-
**5. Create templates for each models above, named as lowercase names of the models:**
109+
**4. Create templates for each models above, named as lowercase names of the models:**
107110

108111
1. streamblocks/templates/streamblocks/richtext.html
109112
2. streamblocks/templates/streamblocks/imagewithtext.html
@@ -142,7 +145,7 @@ class RichText(models.Model):
142145
```
143146
> Note: If you need unique string in block template, use `block_model` and `block_unique_id`
144147

145-
**Full list of variables in template context:**
148+
*Full list of variables in template context:*
146149
- `block_model` (lowercase of modelname - "richtext")
147150
- `block_unique_id` (unique string)
148151
- `block_content` (block data from db)
@@ -151,7 +154,7 @@ class RichText(models.Model):
151154

152155
> Note: For unique idetifier inside the lists you may use a combination of `block_unique_id` and `block.id` of subblock.
153156

154-
**6. Add StreamField to your model in your application**
157+
**5. Add StreamField to your model in your application**
155158

156159
And add the models that you want to use in this stream as model_list
157160
```python
@@ -169,7 +172,19 @@ class Page(models.Model):
169172
)
170173
```
171174

172-
Then if you have your 'page' in context,
175+
*You can set size of popup window*
176+
Add `popup_size` attribute to StreamField
177+
```python
178+
...
179+
stream = StreamField(
180+
model_list=[...],
181+
popup_size=(1000, 500) # default value. Width: 1000px, Height: 500px
182+
)
183+
...
184+
```
185+
186+
**6. Use it in template**
187+
If you have your `page` in context,
173188
you can get content by field's cached property page.stream.render
174189
```html
175190
...
@@ -190,17 +205,6 @@ Or, if you need extra context in blocks, you may use template tag:
190205
```
191206
Third way it's to use list. [See bellow](#get-field-data-as-list)
192207

193-
**You can set size of popup window**
194-
Add `popup_size` attribute to StreamField
195-
```python
196-
...
197-
stream = StreamField(
198-
model_list=[...],
199-
popup_size=(1000, 500) # default value. Width: 1000px, Height: 500px
200-
)
201-
...
202-
```
203-
204208

205209
## Admin
206210
### Custom admin class for block's models

0 commit comments

Comments
 (0)