python - Wagtail: accessing data models outside of an app -


very simple really. i'm new django , extension wagtail. want display posts app on homepage, or within other django app matter.

current app structure:

website/home/ website/blog/ website/portfolio/ 

currently can display posts 'portfolio items' in nice loop on 'portfolio index page'.

when try extend homepage, nothing works.

how access models, etc of 1 app (in case, rendering data 'portfolio items' on 'home'.

portfolio modelss.py:

# -*- coding: utf-8 -*- __future__ import unicode_literals  django.db import models django import forms, utils  wagtail.wagtailcore.models import page wagtail.wagtailcore.fields import richtextfield wagtail.wagtailsnippets.models import register_snippet wagtail.wagtailadmin.edit_handlers import fieldpanel, inlinepanel, multifieldpanel, pagechooserpanel wagtail.wagtailimages.models import image wagtail.wagtailimages.edit_handlers import imagechooserpanel  modelcluster.fields import parentalkey, parentalmanytomanyfield modelcluster.tags import clustertaggablemanager taggit.models import taggeditembase, tag taggittag    class portfoliohome(page):     description = models.charfield(max_length=255, blank=true,)      content_panels = page.content_panels + [         fieldpanel('description', classname="full"),     ]   class portfoliopage(page):     body = richtextfield(blank=true)     feature_image = models.foreignkey(         'wagtailimages.image',         null=true,         blank=true,         on_delete=models.set_null,         related_name='+'     )     categories = parentalmanytomanyfield('portfolio.portfoliopagecategory', blank=true)     tags = clustertaggablemanager(through='portfolio.portfoliopagetag', blank=true)     pub_date = utils.timezone.now()     content_panels = page.content_panels + [         fieldpanel('body', classname="full"),         fieldpanel('categories', widget=forms.checkboxselectmultiple),         fieldpanel('tags'),         imagechooserpanel('feature_image'),     ]  class portfoliopagetag(taggeditembase):     content_object = parentalkey('portfoliopage', related_name='portfolio_tags')  @register_snippet class tag(taggittag):     class meta:         proxy = true         verbose_name = "tag portfolio"         verbose_name_plural = "tags portfolio"   @register_snippet class portfoliopagecategory(models.model):     name = models.charfield(max_length=255)     slug = models.slugfield(unique=true, max_length=80)      panels = [         fieldpanel('name'),         fieldpanel('slug'),     ]      def __str__(self):         return self.name      class meta:         verbose_name = "category portfolio"         verbose_name_plural = "categories portfolio" 

homepage models.py:

    __future__ import unicode_literals      django.db import models     django import forms      wagtail.wagtailcore.models import page     wagtail.wagtailcore.fields import richtextfield     wagtail.wagtailadmin.edit_handlers import fieldpanel, inlinepanel, multifieldpanel, pagechooserpanel      portfolio.models import portfoliopage       class homepage(page):         body = richtextfield(blank=true)         content_panels = page.content_panels + [             fieldpanel('body', classname="homepage"),         ] 

home_page.html template:

{% extends "home/base.html" %}  {% load static wagtailcore_tags wagtailroutablepage_tags wagtailimages_tags %}  {% block body_class %}template-homepage{% endblock %}  {% block home_content %}     <h1>{{ page.title }}</h1>     <div class="content">      {% page in page.get_children.specific %}          <h2>{{ page.get_children.title }}</h2>         <h2><a href="{% pageurl page %}">{{ page.title }}</a></h2>           {% if page.feature_image %}         <section>             <span class="image featured">                 {% image page.feature_image fill-800x450 feature_image %}                 <img alt="{{ page.feature_image.title }}" src="{{ feature_image.url }}">             </span>         </section>     {% endif %}     {% endfor %}       </div>     <p><a href="{% url 'wagtailadmin_home' %}">wagtail admin</a></p> {% endblock home_content %} 

portfolio_home.html template (this renders data perfectly): clarify, want behaviour on homepage...

{% extends "portfolio/base.html" %}  {% load static i18n wagtailcore_tags wagtailroutablepage_tags wagtailuserbar wagtailimages_tags %}  {% block body_class %}portfolio-item{% endblock %}   {% block portfolio_content %}      {{ page.title }}     <br>     {{ page.description }}     <br>     {{ page.body|richtext }}     <br>     {# {% image page.feature_image original class="feature_image" %} #}      {% portfolio in latest_portfolio_list %}         <li><a href="/first_app/{{ portfolio.id }}/">{{ portfolio.title }}</a></li>     {% endfor %}      <p><a href="{{ page.get_parent.url }}">return portfolio</a></p>  {% endblock portfolio_content %} 

if can i'll grateful. if can suggest resources better understand these concepts, please do. i've worked way through couple of tutorials stage, i'm stuck!

cheers

you can update context dictionary of homepage page pass latest_portfolio_list template.

class homepage(page):     body = richtextfield(blank=true)     content_panels = page.content_panels + [         fieldpanel('body', classname="homepage"),     ]      def get_context(self, request):         context = super(homepage, self).get_context(request)         context['latest_portfolio_list'] = portfoliopage.objects.live()         return context 

then loop on lastest_portfolio_list in homepage template.

reference:


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -