Issue
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)
# on 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?
Solution
I think the features you are looking for are currently not implemented (and may not be planned). Many of the Postgres contrib features originated based on this kickstarter project.
I find the most useful documentation for the new features come from the source code itself. Which includes a link to the original pull request for many of these features.
An important note in regards to the Array Functions mentioned, they are Functions and arguably outside the scope of a typical ORM.
I hope this information is useful and you find a nice solution to this issue.
Answered By - erik-e
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.