These are chat archives for django/django

Jun 2018
Jun 10 2018 09:30

hi everyone.
please help me.
i have model with:

 unique_together = (("user", "date"),)

and ModelViewSet with:

            for item in validated_data:
                item["user"] = request.user

                .on_conflict([('user','date')], ConflictAction.NOTHING)\

i got the message:

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

but if i pass, i got the message

Cannot assign "9": "UserActivity.user" must be a "User" instance.

Where is problem ?
How fix is there ?

Jun 10 2018 09:58
Have you actually passed a User Field in the form?
Also insert User ID instead of the user object that should solve the problem..
Jun 10 2018 10:05
yes. i passed
but got the message
Cannot assign "9": "UserActivity.user" must be a "User" instance.
Jun 10 2018 10:08
Post your whole model here
Jun 10 2018 10:11
class UserActivity(PostgresModel):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(User, on_delete=models.PROTECT)
    created_at = models.DateTimeField(auto_now_add=True)
    date = models.DateTimeField(, blank=True)
    heart_rate = models.IntegerField(default=0, blank=True)
    intensity = models.IntegerField(default=0, blank=True)
    steps = models.IntegerField(default=0, blank=True)
    type = models.ForeignKey(UserActivityType, blank=False, default=0, on_delete=models.PROTECT)

    def __str__(self):
        return str(

    class Meta:
        db_table = 'user_activity'
        unique_together = (("user", "date"),)