﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35814	Django migrations & default JSONField	FormindMPO		"Hello,

I'm working on a dynamic translated field (dynamic means i won't use i18n to make it)

I want to use a JSONField in my Article model, as so :

{{{
title = models.JSONField(default=defaultTraduction)
description = models.JSONField(default=defaultTraduction)
}}}

Because making usage of models.JSONField(default=dict(fr="""",en="""",es="""")) raises a warning.

My model is stored in a file named Article.py, inside a models folder.

When loading my migration : python manage.py makemigrations, it tries to import the default function, as so : 


{{{
migrations.AlterField(
            model_name=""article"",
            name=""title "",
            field=models.JSONField(default=recon.models.article.defaultTraduction),
        ),
}}}

But this is not a function part of the class, it is part of the file, so i have the following error when migrating / changing migration : 

field=models.JSONField(default=recon.models.article.defaultTraduction),
AttributeError: type object 'article' has no attribute 'defaultTraduction'

:(

I tried to override the value, with the actual value -> dict(fr="""",en="""",es=""""), but it automaticly detects a modification on next migration 
I tried to move the function in another file -> same issue (type object '**my filename**' has no attribute 'defaultTraduction'
I tried to move the function in another file, and put it in a class ->
Then in my code it gives


{{{
class utils : 
     def defaultTraduction():
         return dict(fr="""",en="""",es="""")

_____

class Article
title = models.JSONField(default=utils.defaultTraduction)
}}}

And now i have a recon.models.utils.utils.defaultTraduction (stacked utils)

I seems that django doesn't really likes this defaut import, how to deal with ?
Thank you



"	Uncategorized	closed	Migrations	4.2	Normal	invalid	JSONField, default	FormindMPO	Unreviewed	0	0	0	0	0	0
