I use django-sidebar(https://github.com/ekaputra07/django-sidebar) for building my widgets. I know how I can use a simple variables, however now I cannot use objects for receive data. Below I providing my code (file django_latest_posts.py as example):
from sidebar.base import SidebarWidget, sidebar_widget
from django import forms
from news.models import Post
TEMPLATE = """
<div class="last_posts">
{% for post in posts %}
<div>{{post}}</div>
{% endfor %}
</div>
"""
#TEMPLATE = get_template('latest_posts_widget.html')
class TextForm(forms.Form):
text = forms.CharField(widget=forms.Textarea)
posts = BlogPost.objects.all()[:2] # I need to show last two posts
class LatestPosts(SidebarWidget):
#admin_form = TextForm
#template_text = get_template('latest_posts_widget.html')
template_text = TEMPLATE
# register the Widget
sidebar_widget = LatestPosts('Latest Posts','Display a Latest Posts')
Please help me how I would correct receive data in TEMPLATE? Thanks for any ideas!