Full Disclosure: I'm just learning Django
The homepage of our site is displaying recent blog posts. In views.py there is a class that defines the attributes that can be called using post.get_attribute to call the recent posts on the homepage. I am trying to add a new attribute that is in the model featured_image but am not able to get it to render on the homepage.
# From models.py
featured_image = models.ImageField(_('featured image'),
upload_to='images/posts',
blank=True, null=True)
# Added featured_image to class in views.py
def get_posts(request, post_type):
if post_type == 'personal':
posts = list(Post.personal_objects.all().values('title', 'slug',
'author__username',
'views',
'featured_image'))[:8]
elif post_type == 'business':
posts = list(Post.business_objects.all().values('title', 'slug',
'author__username',
'views',
'featured_image'))[:8]
else:
raise Http404
return HttpResponse(json.dumps(posts), mimetype='application/json')
How I am trying to call the featured image in home.html:
<a href="{{ post.get_absolute_url }}">
<img src="{{ post.get_featured_image_url }}" />
</a>
What am I missing to get these images pulling in? Really appreciate any insight. For broader context visit this link.