File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,6 +108,15 @@ and will be a list of objects if there is.
108108</ul >
109109```
110110
111+ > Note: You may use also ` block_template ` option. For specify a block template file.
112+
113+ ``` python
114+ class RichText (models .Model ):
115+ ...
116+ block_template = " streamblocks/richtext.html"
117+ ...
118+ ```
119+
111120** 4. Add apps to settings.py**
112121
113122Add to INSTALLED_APPS
@@ -198,6 +207,15 @@ As context use "form":
198207```html
199208{{ form.text.value }}
200209```
210+
211+ You may also specify custom template as option:
212+ ```python
213+ class RichText(models.Model):
214+ ...
215+ custom_admin_template = " streamblocks/admin/richtext.html"
216+ ...
217+ ```
218+
201219# ## Override how to render block's fields in admin
202220Create custom template for field with name as lowercased field widget name, and put it inside `... / streamblocks/ admin/ fields/ ` folder.
203221
@@ -275,6 +293,22 @@ In page admin you will see it on the bottom of this block.
275293> Note: Now only " checkbox" and " select" type is working.
276294You may apply options for all blocks with `STREAMFIELD_BLOCK_OPTIONS ` (See [Settings](# settings))
277295
296+ If you want to add block options to options, which was set in django settings, you may use `extra_options` .
297+ ```python
298+ class Slide(models.Model):
299+ ...
300+ extra_options = {
301+ " autoplay" : {
302+ " label" : " Autoplay" ,
303+ " type" : " checkbox" ,
304+ " default" : False
305+ }
306+ }
307+ ...
308+ ```
309+
310+ If you want to switch off options, which set in django settings, for current block. Set `options={}`
311+
278312# # Special cases
279313# ## Complex Blocks
280314You may use StreamField as part of blocks and create with that way complex structure
Original file line number Diff line number Diff line change 55
66setuptools .setup (
77 name = "django-streamfield" ,
8- version = "1.1.4 " ,
8+ version = "1.2.0 " ,
99 author = "Yury Lapshinov" ,
1010 author_email = "y.raagin@gmail.com" ,
1111 description = "StreamField for native Django Admin or with Grappelli" ,
Original file line number Diff line number Diff line change 11name = "streamfield"
2- VERSION = '1.1.4 '
2+ VERSION = '1.2.0 '
Original file line number Diff line number Diff line change @@ -118,7 +118,11 @@ def to_json(self):
118118
119119
120120def _get_render_data (model_class , model_str , content , ctx ):
121- block_tmpl = 'streamblocks/%s.html' % model_str .lower ()
121+ if hasattr (model_class , 'block_template' ):
122+ block_tmpl = model_class .block_template
123+ else :
124+ block_tmpl = 'streamblocks/%s.html' % model_str .lower ()
125+ print (block_tmpl )
122126 try :
123127 t = loader .get_template (block_tmpl )
124128 except loader .TemplateDoesNotExist :
Original file line number Diff line number Diff line change @@ -18,10 +18,10 @@ def __init__(self, attrs=None):
1818 for block in self .model_list :
1919 as_list = hasattr (block , "as_list" ) and block .as_list
2020
21- options = BLOCK_OPTIONS
22- if hasattr (block , "options " ):
21+ options = block . options if hasattr ( block , "options" ) else BLOCK_OPTIONS
22+ if hasattr (block , "extra_options " ):
2323 options = deepcopy (options )
24- options .update (block .options )
24+ options .update (block .extra_options )
2525
2626 model_doc = block ._meta .verbose_name_plural if as_list else block ._meta .verbose_name
2727 model_list_info [block .__name__ ] = {
Original file line number Diff line number Diff line change 44from .forms import get_form_class
55
66def admin_instance_class (model , base = DetailView ):
7-
8- tmpl = loader .select_template ([
9- 'streamblocks/admin/%s.html' % model .__name__ .lower (),
10- 'streamfield/admin/change_form_render_template.html'
11- ])
12-
13- # will be removed in future. use above approach to override admin template.
7+
148 if hasattr (model , 'custom_admin_template' ):
159 tmpl_name = model .custom_admin_template
16- import warnings
17- warnings .warn (
18- "'custom_admin_template' will be removed in future. "
19- "Use override admin template approach instead" ,
20- DeprecationWarning , stacklevel = 2 )
2110 else :
11+ tmpl = loader .select_template ([
12+ 'streamblocks/admin/%s.html' % model .__name__ .lower (),
13+ 'streamfield/admin/change_form_render_template.html'
14+ ])
2215 tmpl_name = tmpl .template .name
2316
2417 def get_context_data (self , ** kwargs ):
You can’t perform that action at this time.
0 commit comments