Тип объекта «Уведомление» не имеет атрибута «объект» - PullRequest
1 голос
/ 02 апреля 2019

Я получаю эту ошибку из моего view.py

тип объекта «Уведомление» не имеет атрибута «объект»

и мои view.py

from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from notification.models import Notification

def show_notification(request, notification_id):
    n = Notification.object.get(id=notification_id)

    return render_to_response('notification.html', {'notification':n})
def delete_notification(request, notification_id):
    n = Notification.object.get(id=notification_id)
    n.viewed = True
    n.save()

а также мои models.py

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver


class Notification(models.Model):
    title = models.CharField(max_length=250)
    message = models.TextField()
    viewed = models.BooleanField(default=False)
    user = models.ForeignKey(User, on_delete=models.DO_NOTHING)


def create_welcome_message(sender, **kwargs):
    if kwargs['created']:
        noti=Notification.objects.create(user=kwargs['instance'],
                                    title="Welcome Message",
                                    message="Thank you for singing up!")


post_save.connect(create_welcome_message, sender=User)

Я скучаю уже давно. используя этот язык. тогда помогите мне с этой ошибкой

1 Ответ

1 голос
/ 02 апреля 2019

Вы пытаетесь получить уведомление, используя Notification.object.get(id=notification.id).

Замените object на objects для запроса уведомлений.

для экземпляра, Notification.objects.get(id=notification.id)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...