0

I am not sure what happening with this notifications system look, here is the error

int() argument must be a string, a bytes-like object or a number, not 'SimpleLazyObject'

Views.py

def index(request):
    notifi = Notificaciones.objects.filter(user=request.user, Estado=False)
    if request.method == 'POST':
        form = RegistroUserForm(request.POST, request.FILES)
    else:
        form = RegistroUserForm()
    context = {
        'form': form,
        'notifi': notifi
    }

    return render(request,'app/index.html',context)

Models.py

class Notificaciones(models.Model):
    user = models.ManyToManyField(User)
    Tipo_de_notificaciones = ( (1,'Ofertas'),(2,'Error'),(3,'Informacion'))
    Tipo = models.IntegerField('Tipo de notificacion',choices=Tipo_de_notificaciones, default=3,)
    titulo = models.CharField("Nombre de la notifiacion",max_length=50)
    mensaje = HTMLField("Descripcion de la notificacion")
    imagen = models.ImageField("Imagen de la notificacion",upload_to="notificaciones")
    Fecha_Caducidad_notificacion = models.DateTimeField("Fecha de caducidad de la notificacion",auto_now_add=False)
    Estado = models.BooleanField("Estado de la notificacion", default=False)
    class Meta:
        verbose_name = 'Notificacion'
        verbose_name_plural = 'Notificaciones'
    def __str__(self):
        return self.titulo

@receiver(post_save, sender=User)
def mensaje_bienvenida(sender, **kwargs):
    if kwargs.get('creado', False):
        Notificaciones.objects.create(user=kwargs.get('instance'),
                                      titulo= "Bienvenido a la plataforma de Vulpini.co",                                      
                                      mensaje= 'Gracias por registrarte'
            )

Notificaciones.html

{% if notifi.count > 0 %}
        {% for notifi in notifi %}
           <ul>
              <li>
                {{ notifi.Tipo }}
                {{ notifi.titulo }}
                <img src="{{  notifi.imagen.url }}" alt="{{ notifi.titulo }}"/>
                {{ notifi.mensaje }}
                {{ notifi.Fecha_Caducidad_notificacion }}
              </li>
            </ul>
        {% endfor %}
    {% endif %}

Why show error, if two days ago work and i don't change anything. Help me, Thanks you

Shapi
  • 5,493
  • 4
  • 28
  • 39
Alfredhb.q
  • 75
  • 1
  • 9
  • Can you post the traceback? You aren't calling `int` in that code, so we can't tell where the error is happening. –  Oct 26 '15 at 01:16

1 Answers1

1

Have you tried something like this in your views.py?

notifi = Notificaciones.objects.filter(user=request.user.id, Estado=False)

EDIT:

Maybe this previous post can be helpful for you. django: Purpose of django.utils.functional.SimpleLazyObject?

Or look what I found, this could be also helpful: Django int() argument must be a string or a number

Hope this helps. :)

Community
  • 1
  • 1
Jose Romero
  • 559
  • 2
  • 12