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

2
  • 1
    Note you should use default=list instead of default=list(). Commented Apr 26, 2018 at 14:32
  • This question was written for Django 1.8 so might be out of date, but some of the answers might help Commented Apr 26, 2018 at 14:33

1 Answer 1

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'] )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.