views:

29

answers:

1

what field in the django models class should be used if the type of data (text/images/html) is unknown? i'm looking for a field that can handle copy and pasted html code, images, text, etc.

A: 

Any textual info: TextField

Any binary info (except jpg, gif, png): FileField

Any image: ImageField

The data of FileField an ImageField is stored as files on the hard disk, leaving just the path to the file including the filename in a database field. (This is a performance feature!)

I would not use one field in your table for all three types of data, but let a) the user specify whether that's an image or some text, or b) decide yourself by checking the file using tools like unix's file command.

mawimawi
The Python equivalent would be `magic`.
Ignacio Vazquez-Abrams
how about rendered HTML? i need a field that can handle rich-text, but client-side not for the admin page
momo
store rendered HTML in a TextField. In your template, use the 'safe' filter to render as HTML, otherwise all the HTML bits will be escaped and you'll get a bunch of HTML code on your page
Chris Lawlor