Re: LaTeX custom Field, png url

2009-02-16 Thread Alex Gaynor
On Mon, Feb 16, 2009 at 12:05 PM, alain31  wrote:

>
> 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?
>
> >
> 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.

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

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: LaTeX custom Field, png url

2009-02-16 Thread alain31

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?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: LaTeX custom Field, png url

2009-02-16 Thread Alex Gaynor
On Mon, Feb 16, 2009 at 10:40 AM, alain31  wrote:

>
> 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.
>
> >
>
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

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



LaTeX custom Field, png url

2009-02-16 Thread alain31

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.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---