Answer the question
In order to leave comments, you need to log in
Where did I make a mistake in writing the function?
I'm new to programming and I've come across a problem that I can't figure out. When opening the news page by link, the following error is displayed:
entries = el.en_set.order_by('-date_added'). I understand the problem, but I don't understand how to solve it. Confused in my own code.
AttributeError: 'function' object has no attribute 'en_set'
class News(models.Model):
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=50,unique=True)
author = models.ForeignKey(User,on_delete=models.CASCADE,
related_name='news_posts', null=True, blank=True)
anons = models.CharField(max_length=350)
body = RichTextUploadingField(null=True, blank=True)
date_added = models.DateTimeField(auto_now_add=True)
# Возврат понятного отображения заголовка в панель администрирования
def __str__(self):
return self.title
class Meta:
verbose_name = u"Новость"
verbose_name_plural = u"Новости"
path(r'new/<el_id>', views.el, name='el')
def el(request, el_id): #Вывод отдельной новости
article = News.objects.get(id=el_id)
entries = el.en_set.order_by('-date_added')
context = {'el':el, 'entries': entries}
return render(request, 'prosvet_logs/article.html', context)
-generated page
{% extends "prosvet_logs/base.html" %}
{% block content %}
<div class="article">
<h2>{{ el }}</h2>
{% if new %}
{% for el in new %}
<p>{{ new.date_added|date:'M d, Y H:i' }}</p>
<p>{{ new.body|linebreaks }}</p>
{% endfor %}
{% else %}
<p>Новостей нет</p>
{% endif %}
</div>
{% endblock content}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question