If you have a StructBlock class (used inside a StreamField)... Can you still use the Wagtail panels to group some fields (eg MultiFieldPanel) and (ideally!) use the collapsible class on the panel to hide them in some kind of "Advanced" panel?
I have tried adding the block.TextBlock definitions into the array for a panel the, however neither the Panel nor the Fields appeared in the form.
I cant see anything in the docs about using Panels in StructBlocks:
https://docs.wagtail.io/en/v2.8.1/reference/pages/panels.html
https://docs.wagtail.io/en/v2.8.1/topics/streamfield.html
It's not possible to use panels inside StreamField blocks. However, by overriding form_template on your StructBlock class you can set up whatever HTML structure you like:
https://docs.wagtail.io/en/stable/advanced_topics/customisation/streamfield_blocks.html#custom-editing-interfaces-for-structblock
Related
I use modelforms in several places in my app, and have written custom bootstrap form rendering. It's working well, but I'd like to be able to add addon_before to some of my fields (example, for twitter_username i'd set addon_before='https://twitter.com/. I'd also like to specify icon classes and placeholder text for some fields.
I know I can do this in the form rendering, but I render the same fields in several different forms, and I dont want to repeat the form settings. using the twitter_username example, is there a way to globally set wherever that field is used in a modelform, to include a set of attributes and values
{'addon_before': 'https://twitter.com/', 'placeholder': '#username', 'icon': 'fa-twitter'}
Would love any suggestions!
I am trying to make one Blog using Django 2.0 and I have already created a primitive one. It has a Post model which is as follows:
class Post(models.Model):
PriKey = models.CharField(max_length=255,primary_key=True)
Heading = models.CharField(max_length=100)
DateOfPost = models.DateField(default=datetime.date.today())
Content = models.TextField()
As it can be seen, the content area is only textual and as of now, I can't add any special style or pictures inside my content.
I thought of using HTML tags inside the text content but they are appearing unchanged when the web page is rendered.
So my question is, is there any way of storing pictures along with the text in the content field of the Post model? I want to make something like this
Is there any way of showing the pictures in their respective positions using Django model? If no, is there any other way of doing this?
Also, is there any way of storing HTML codes inside django models and render them as it is when the website is run?
You can store html tags inside the field.
while rendering, to template mark it as safe
{{ post.content|safe }}
This will render all the html tags.
But this is not a good way as it makes you vullerable to cross site scripting attacks
A better method is to use something like a ckeditor
It provides a RichTextField and RichTextUploading Field and using this you can upload pictures, videos, code snippets, style your text and a lot more inside one field.
There are many other optons, but I prefer ckeditor
Ckeditor is a cross platform editor, django-ckeditor is a library containing django implementation of ckeditor which gives you full backend and frontend combined
ckeditor
django-ckeditor
django-pagedown A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin
I think you should give it a try
Cheers :)
I've been playing around with mezzanine for a couple days and I've been following this blog, which has been very helpful.
I'm now at the point where I need to make a bunch of pages that need to be based off of a custom template. My custom template is called content.html
I've put it in myProject > myApp/theme folder > templates > pages > content.html but when I look in the admin console, I don't see content in the drop down menu.
How do I get mezzanine to recognize my content.html page as a template?
content.html will not automatically appear in your site's drop down menu.
You need to go to the admin site and explicitly declare a page my content where you would like content.html to appear in your page hierarchy.
For mezzanine to match the two (i.e. template content.html and admin page my content):
Either my content's Title field (in admin site) should be content,
Or, URL field (in the meta data section of my content) should be content (if you decide the title will not be content),
Or, if you want content.html to have a custom slug, say nicecontent, then fill URL field with nicecontent and add to url.py a pattern for content.html with a matching slug, so:
url("^nicecontent/$", direct_to_template, {"template": "path/to/content.html"}, name="name_for_content").
There's a method Mezzanine uses for looking up template names, from the broadest ("page.html", which all other templates also extend), to templates named for their content types (richtextpage.html, gallery.html, etc), down to the most granular level, which is templates matching the url/slug of individual pages.
This is all covered in the documentation:
http://mezzanine.jupo.org/docs/content-architecture.html#page-templates
It sounds like you might be looking for "page.html", but it's not clear from your question.
I have 2 data template fields "title" and "id", used for the HTML page title and the id attribute in the body tag respectively. When the page is viewed using Page Editor, Sitecore attempts to render editor controls on these items and because they are outside of the main form tag, controls don't get rendered correctly. I don't need these to be editable in the Page Editor.
What's the best approach/solution to handle fields like these?
Is hiding these 2 template fields from the Page Editor a solution?
If so, how do you hide the fields from the Page Editor and still have it available on the Content editor (so we can still edit it within the Content editor)?
In Page Editor, all you should need to do is render their values without a FieldRenderer. e.g, bind the field values to a standard .NET control. Or use a scriptlet -- <%=Sitecore.Context.Item["Title"]%>
Is there a straightforward, common way to apply custom styling on admin change list element depending on its properties?
update
To be more precise: let's say I have a simple model object.
Foo
field1
field2
field3
#property
property1()
#property
property2()
ModelAdmin.list_display is defined as a subset of the available fields, so not every attribute (field/property) is displayed in the change list table.
I'd like to apply custom CSS class to the object's row when certain condition is fulfilled, for example: if foo_instance.property1 is True then add class bar to the corresponding tr element.
Now copy the template admin/base_site.html from within the default Django admin template directory (django/contrib/admin/templates) into an admin subdirectory of whichever directory you're using in TEMPLATE_DIRS. For example, if your TEMPLATE_DIRS includes "/home/my_username/mytemplates", as above, then copy django/contrib/admin/templates/admin/base_site.html to /home/my_username/mytemplates/admin/base_site.html. Don't forget that admin subdirectory.
Note that any of Django's default admin templates can be overridden. To override a template, just do the same thing you did with base_site.html -- copy it from the default directory into your custom directory, and make changes.
from django's tutorial
What exactly do you mean by "change list element" and "it's properties"? Using CSS 2 or CSS 3 selectors you can do some things. Otherwise, you might be able to do it easily using jQuery (or whatever). Since it is merely presentation related, I think this would be the cleanest solution.
Old question but if you stumble across it, the following tips might be helpful.
You can use django-liststyle to customise your admin changelist rows.
It's quite simple to implement your example:
class FooAdmin(admin.ModelAdmin, ListStyleAdminMixin):
...
def get_row_css(self, obj, index):
if obj.property1:
return 'bar'
return ''
Django Suit (not free) also offers "List row and cell attributes" style customisation