Friday, November 9, 2018

Re: Update profile on login

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Thu, Nov 08, 2018 at 09:17:30AM -0800, pastrufazio wrote:
>
> Hi all,
>
> I'm trying to update the field "date_activation" the first time a user log
> in.
>
> This is the error I get when i try to run the code below
>
> *TypeError at /admin/login/ int() argument must be a string, a bytes-like
> object or a number, not 'ModelBase'*
>
> Any help would be really appreciated!

Hi,

Could you please post the full stack trace rather than just the final
error message? That would make it easier to help you.

Cheers,
Michal

> 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)
>
>
> @receiver(post_save, sender=User)
> def create_user_profile(sender, instance, created, **kwargs):
> if created:
> Profile.objects.create(user=instance)
>
> @receiver(post_save, sender=User)
> def save_user_profile(sender, instance, **kwargs):
> instance.profile.save()
>
> @receiver(user_logged_in, sender=User)
> def user_logged_in_callback(sender, user, request, **kwargs):
> Profile.objects.filter(user=User).update(date_activation=datetime.now)
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/237c6adf-1d2c-4ce7-b8d6-60a7d827833a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJb5VMbAAoJEHA7T/IPM/kl5AcP/jhCQmT9cJrOFyb36ABIz/+0
/7rcsAq5NCyUAi6g/R4tchDI5K0Yw7uW5LSHl9eDeph1EhCeg/7ZXj8l7z45s5bG
NxR8usfqic/N8gZHPpHDYjnMG/ZjimuiGVQLq8hBA4lRrhvtHv8/VchLuI8U8h23
vez5lu3D8tGDYhBVcMgagji+8to3QmAfc2XYcJVwjgzF/lVyFAxfEzEurVuOshec
GjYYzd/nd8ZNFcZKSNNlh/P7OIW4tmZQ9dheRUV05a9zoG1ETTMEoTk2wy9wawzb
WcvG21Vz2CynnJcooWcJqHDV0bG6CPJgeJqefvZZI+8Fuok2ZgND3JlhsrH89f/R
+MthbLc49DgY1wAOZqMTk31v8I6/+3HV+X69Xu5dnyLwBkT9yY9pdKGmeNyWkatc
xHsnvyHdQi/EBLNTWlyfqv4EPuLoYpYgZJloecrtVhNFxFj+p9IFChwplNHHD566
b7iAlZnhnkhFIfk4oAN7wBGtTqA7rlaVaMWzOPgRIcXj9HYW4k62eOIANjDBER5n
HTdaE63MmPnF/hO6Gl0P45fG+FjMiSwy5erXViyIUjv9j70YQ28IwdRBJCkMaKjZ
SJk+MtxFXnWMdK5CGqDpXjhlriUMMAm+TUL3Iz1mkM3JmXM59l95Njy0mw5jjz6l
xjHIhdIztIG/8kKN567n
=i1zJ
-----END PGP SIGNATURE-----

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20181109092756.GB8269%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment