LaTeX custom Field, png url

29 views
Skip to first unread message

alain31

unread,
Feb 16, 2009, 10:40:52 AM2/16/09
to Django users
Hello,
I plan to use django for some projects with heavy use of math formulas
and I would like to create a reusable custom field to store LaTeX
strings and to get a png image on disk after compilation. The usage
would go like this :
model:
formula = LatexField()
template to get the png:
{{model.formula.url}}
Before saving the field, I compile the string on server with LaTeX and
make a png stored in a local file.

I have the following question : I need to store in the database the
LaTeX string as well as the url of the
png image and I wonder how to do it (I looked at FileField,
ImageField but only the url is saved in the database). Another point,
it would be nice to create a specific form to see the errors during
LaTeX compilation and to correct them before saving the field in the
database.

Any suggestions, starting point in docs ?
Thanks.

Alex Gaynor

unread,
Feb 16, 2009, 11:43:39 AM2/16/09
to django...@googlegroups.com
Here's a guide on writing a custom model field: http://docs.jezdez.com/howto/custom-model-fields.html .  My guess is you'll actually need 2 real fields in the DB, with one psuedofield similar to the generic foreign key that actually handles combining those 2 into a real item.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire
"The people's good is the highest law."--Cicero

alain31

unread,
Feb 16, 2009, 12:05:18 PM2/16/09
to Django users
What I understood reading custom-model-fields.html is that Field class
only handle one column in database
(db_type method returns a database type...). I first thought to
inherit from TextField and build the name of the png file using a hash
from
the LaTeX string (so no need to store it in the database), or store a
string made of concatenation of LaTeX string + url
but I imagine that there must be a cleaner way to do it no?

Alex Gaynor

unread,
Feb 16, 2009, 12:08:02 PM2/16/09
to django...@googlegroups.com
If you take a look at how Generic Foreign Key fields are used the user defines 2 fields on the model, and then the generic foreign key acts as a psuedofield(it exists in python, but not the DB) and combines the data from both those fields.  That's how I would do it, take a look at django.contrib.cotnenttypes.generic to see how that's implemented.
Reply all
Reply to author
Forward
0 new messages