Accessing 'bytea' field using django.

906 views
Skip to first unread message

ds99

unread,
Nov 4, 2009, 12:27:24 AM11/4/09
to Django users
Hi,
I am using django with postgres as backend. Some of the fields in the
table are of type "bytea"(bytearray). Which django fields should I use
while defining a model for such tables?

for eg: To access "boolean" we use BooleanField while modelling. I
want to know how to access "bytea" type using django.

-ds99

James Bennett

unread,
Nov 4, 2009, 12:38:23 AM11/4/09
to django...@googlegroups.com
On Tue, Nov 3, 2009 at 11:27 PM, ds99 <cozyda...@gmail.com> wrote:
> I am using django with postgres as backend. Some of the fields in the
> table are of type "bytea"(bytearray). Which django fields should I use
> while defining a model for such tables?

You should write a field which does this. There is no field built in
to Django which does this.


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Kenneth Gonsalves

unread,
Nov 4, 2009, 12:43:39 AM11/4/09
to django...@googlegroups.com
On Wednesday 04 Nov 2009 10:57:24 am ds99 wrote:
> I am using django with postgres as backend. Some of the fields in the
> table are of type "bytea"(bytearray). Which django fields should I use
> while defining a model for such tables?
>
> for eg: To access "boolean" we use BooleanField while modelling. I
> want to know how to access "bytea" type using django.
>
generally django follows the policy of storing files/images on the filesystem
and only the location in the database. Hence there is no bytea type field. You
may check out the documentation for custom field types to roll your own.
Generally speaking though, media should be served separately from django
itself - often by a different webserver from a different machine.
--
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
http://nrcfosshelpline.in/web/

David De La Harpe Golden

unread,
Nov 4, 2009, 6:18:47 AM11/4/09
to django...@googlegroups.com

Unfortunately django doesn't presently support postgres' bytea out of
box. There is a patch in the tracker, though I don't know if it works
with recent django:
http://code.djangoproject.com/ticket/2417

One workaround for storing chunks of binary data is base64 encoding into
a text field, but that doesn't help you if you're trying to wrap an
existing postgresql database that happens to use bytea, and is not
exactly a high-performance solution (the better data integrity over fs
and ease of manipulation* might be worth it for you though, and
postgresql text (and bytea) fields work without problem to quite large
sizes (1GB))

* The "X-SendFile" API can allow you to use django-level code to
determine permissioning for filesystem files served through the
webserver though.

ds99

unread,
Nov 12, 2009, 5:33:52 AM11/12/09
to Django users
Thanks all for your comments and suggestions. I will definitely take
them into account.

-ds99
Reply all
Reply to author
Forward
0 new messages