[Ncr-Python.in] Django - Loading a large default value in a model

Gora Mohanty gora at mimirtech.com
Wed Nov 21 07:44:26 CET 2012


On 21 November 2012 12:03, Nandeep Mali <n9986.mali at gmail.com> wrote:
[...]
> I have a field called schema in a Django model that usually contains a
> rather large json string. There is a default value (around 2000
> characters) that I would like added when any new instance is created.
>
> I find it rather unclean to dump the whole thing in the models.py in a
> variable. What is the best way to load this default value in my schema
> (which is a TextField)?
[...]
> Approaches I have been suggested:
>
> a. Set the default in the model field to a callable (method) which
> reads a file and return its contents.
> b. Do the above on post_save hook.

(a) seems fine, but aren't you over-analysing this? If the default value
is fixed, why not put it into a string in say, constants.py in the same
directory as models.py, and just import the string in models.py,

Regards,
Gora


More information about the Ncr-Python.in mailing list