Thursday, March 26, 2015

Django 1.8 ArrayField append & extend

Please forgive me for cross posting, I asked this question on stack overflow 2 weeks and have "earnt the tumbleweed award for no one commenting or replying to it" (no really, it's a real thing).

Django 1.8 will come with new advanced field types including ArrayField these rely on PostgreSQL and are implemented at a DB level.

PostgreSQL's array field implements an append method.

However I can't find any documentation on appending an item to an ArrayField. This would clearly be very useful as it would allow the field to be updated without transferring its entire contents from the db then back to it.

Is this possible? If not will it be possible in future? Any pointers to docs I've missed would be much appreciated.

To clarify what I'm asking about, this would be great:

Note: this is fantasy code and I assume won't work (I haven't tried)

# in model:  class Post(models.Model):      tags = ArrayField(models.CharField(max_length=200))    # somewhere else:  p = Post.objects.create(tags=[str(i) for i in range(10000)])  p.tags.append('hello')

Is there currently any way of doing this without resorting to raw sql?

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/964a4807-3836-49d2-8bb6-2499fd08f7d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment