Reputation: 20
I have this model
class Moments(models.Model):
content = models.TextField(blank=True)
user = models.ForeignKey(User, on_delete=models.PROTECT)
publishing_date = models.DateTimeField(name='Date Published', default=timezone.now)
def get_publishing_date(self):
return self.publishing_date
Now on calling the get_publishing_date, its telling that
Internal Server Error: /torko/feed/maX/0/
Traceback (most recent call last):
File "C:\Users\soumi\AppData\Roaming\Python\Python37\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\soumi\AppData\Roaming\Python\Python37\site-packages\django\core\handlers\base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "e:\web_projects\torko\tko\views.py", line 169, in get_feed_of_user_by_id
html = moments_mini_template.render({'moments_object': expression, 'date_published': expression.get_publishing_date().strftime("%H:%M %p, %d %B, %Y")})
File "e:\web_projects\torko\tko\models.py", line 51, in get_publishing_date
return self.publishing_date
AttributeError: 'Moments' object has no attribute 'publishing_date'
Another fact is that the publishing_date is present in django admin page.
Upvotes: 0
Views: 198
Reputation: 3717
I suppose it is because you change the field name with the name attribute: ....models.DateTimeField(name='Date ....
Upvotes: 1