[Answered ]-How to append value to the ArrayField in Django with PostgreSQL?

0👍

Following this Answer I did this.

from django.db.models import Func, F, Value
.
.
.
attend, created = models.AttendanceModel.objects.get_or_create(user=fingerprint.user, date=attendance_date)
attend.time = Func(F('time'), Value(attendance.timestamp.time()), function='array_append')
attend.save()

1👍

attend.time = attend.time.append(attendance.timestamp.time())

Here the return value of list.append(...) is being assigned to attend.time, which is None, thus the attend.time is not getting updated.

Try this instead,

attend, created = models.AttendanceModel.objects.get_or_create(
    user=fingerprint.user, date=attendance_date
)
attend.time.append(attendance.timestamp.time())
attend.save()
👤JPG

Leave a comment