1

I'm trying to create a list in PostgreSQL of filenames and update the list on the fly.

my model(Package):

completed_uploads=ArrayField(models.TextField(blank=True), null=True, default=list)

creating the list:

Package.create(...,
completed_uploads = [])

my update code:

packageInstance = Package.objects.get(id=packageId)
completed_uploads = packageInstance.completed_uploads.append(request.data['filepath'])
Package.objects.filter(id=packageId).update(node = request.data['node'], completed_uploads=completed_uploads, prefix=request.data['prefix'] )

edit I changed the above to list instead of list() --- now I get the error:

'NoneType' object has no attribute 'append' on the second time the function is called. when I check my database the field 'completed_uploads' is null

GeneralBear
  • 1,011
  • 3
  • 11
  • 35
  • 1
    Note you should use `default=list` instead of `default=list()`. – Alasdair Apr 26 '18 at 14:32
  • [This question was written for Django 1.8](https://stackoverflow.com/questions/29014966/django-1-8-arrayfield-append-extend) so might be out of date, but some of the answers might help – Alasdair Apr 26 '18 at 14:33

1 Answers1

1

Just needed to change to:

packageInstance = Package.objects.get(id=packageId)
packageInstance.completed_uploads.append(request.data['filepath'])
Package.objects.filter(id=packageId).update(node = request.data['node'], completed_uploads=packageInstance.completed_uploads, prefix=request.data['prefix'] )
GeneralBear
  • 1,011
  • 3
  • 11
  • 35