Also, here's I talk I gave regarding how to leverage Mezzanine to display content types using Displayable instead of Page. It might be useful for what you're building: https://www.youtube.com/watch?v=yVAmMXES2EU

On 2017-10-06 2:33 PM, Eduardo Rivas wrote:

Access to model fields is the same in Python and in templates:

{{ my_model.title }} {# This comes from Displayable #}
{{ my_model.some_other_field }}

Now, you might be asking how to get "my_model" into the template context to begin with. The answer is to write a view that does it:

from django.shortcuts import render

def my_model_detail_view(request):
    context = {
        "my_model": MyModel.objects.get(...),
    }
    render(request, "my_template.html", context)

Regarding the blog posts, there's already a template tag that can fetch you recent posts:

{% load blog_tags %}
{% blog_recent_posts limit=3 as recent_posts %}
{% for post in recent_posts %}
...
{% endfor %}

I suggest you take a look at the source for this tag to see how Mezzanine handles it: https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/blog/templatetags/blog_tags.py#L57


On 2017-10-06 2:24 PM, Hamza Jutt wrote:
Hello *Eduardo*!

*Thanks* for the detailed answer.

Now here is the thing When I said that I was extending from *Displayable *That was supposed to mean that I'm inheriting abstract model in my Custom content type. I can create items in database using *admin-site *and I've know a hefty amount about Django ORM. I know what displayable provides in that case. But what I was hoping for a similar method to access data in django template as in Docs You can access data of custom fields in model extended from *Page.*

|
{{page.some_model.title }}
{{page.some_model.slug }}
{{page.some_model.custom_field }}
|
What I got from your answer is there is no way to access data in django template of model which is inheriting Displayable as it is not in context. Only way to get that data is to use custom urls, views and templates. It's like just getting some basics but implement almost everything to get data from db (on url parameters or something). Then pass it as context to template response along with django template just like Blog.

Actually Our old app uses mezzenine but inherits everything from *Page*. And using that we can easily access data using page in context in django template. But that does seems wrong to create everything as page. But what I understood that If I were to fix it I will have to write all those urls and views by myself.

If I understood something wrong please help. Also I do have another question so if I have model inheriting *Displayable* and now I need info from that model in pages other that specific pages provided by custom urls and views. how would I do it. For *Example* I need 3 recent blog posts on home page. So how would I access them. Would I have to write custom View for Home page and if so then I'm just overriding Home page default view as it is *RichTextPage* at this point.

If anything seems confusing I would be happy to provide further information.

Help is highly appreciated.

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Mezzanine 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to