Updating date field using signals

44 views
Skip to first unread message

pastr...@gmail.com

unread,
Nov 9, 2018, 6:51:46 AM11/9/18
to Django developers (Contributions to Django itself)
Hi all,

I have a very simple Profile class:

class Profile(models.Model):
  user = models.OneToOneField(User, on_delete=models.CASCADE)
  location = models.CharField(max_length=30, blank=True)
  birth_date = models.DateTimeField(null=True, blank=True)
  date_activation = models.DateTimeField(null=True, blank=True)


I want to set date_activation = datetime.now the first time the user login.
I tried using "user_logged_id" signal, without success:

@receiver(user_logged_in, sender=User)
  def user_logged_in_callback(sender, user, request, **kwargs):
    Profile.objects.filter(get_user(request)).update(date_activation=datetime.now)



Testing it I get this errore message below.
Any help or suggestions would be greatly appreciated!



TypeError at /admin/login/

int() argument must be a string, a bytes-like object or a number, not 'ModelBase'
Request Method: POST
Request URL: http://localhost:4000/admin/login/?next=/admin/
Django Version: 1.11.16
Exception Type: TypeError
Exception Value:
int() argument must be a string, a bytes-like object or a number, not 'ModelBase'
Exception Location: /usr/local/lib/python3.6/site-packages/django/db/models/fields/__init__.py in get_prep_value, line 966
Python Executable: /usr/sbin/uwsgi
Python Version: 3.6.5
Python Path:
['.',
 '',
 '/code',
 '/usr/local/lib/python3.6/site-packages',
 '/usr/lib/python3.6/site-packages',
 '/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload']




Michael Manfre

unread,
Nov 9, 2018, 9:16:13 AM11/9/18
to django-d...@googlegroups.com
This mailing list is for the development of the Django Framework. Questions related to its usage should be posted to the django-users mailing list.

Regards,
Michael Manfre

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/fd7793b7-305a-4916-bae8-e8de687be346%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
GPG Fingerprint: 74DE D158 BAD0 EDF8
Reply all
Reply to author
Forward
0 new messages