Hello,
I'm making a reference data model and I'd like to internationalize the
description field of my model but unfortunatelly it doesn't work with
django trunk.
Here is the model:
@I18n('description')
class ReferenceDataValue(ModelAccounting):
domain = models.ForeignKey('ReferenceDataDomain',related_name='values')
code = models.CharField(max_length=10)
description = models.CharField(max_length=255)
parent = models.ForeignKey('self', related_name='child', blank=True, null=True)
display_order = models.IntegerField(default=0)
is_default = models.BooleanField()
links = models.ManyToManyField('self', through='ReferenceDataLink',
symmetrical=False, related_name = 'linked_value', blank=True, null=True)
def __unicode__(self):
return self.description
and here is the generated sql:
CREATE TABLE "ReferenceData_referencedatavalue" (
"id" integer NOT NULL PRIMARY KEY,
"is_deleted" bool NOT NULL,
"created_at" datetime NOT NULL,
"modified_at" datetime NOT NULL,
"created_by_id" integer NOT NULL REFERENCES "auth_user" ("id"),
"modified_by_id" integer NOT NULL REFERENCES "auth_user" ("id"),
"domain_id" integer NOT NULL REFERENCES
"ReferenceData_referencedatadomain" ("id"),
"code" varchar(10) NOT NULL,
"description" varchar(255),
"description" varchar(255),
"description" varchar(255),
"description" varchar(255),
"description" varchar(255),
"description" varchar(255),
"parent_id" integer,
"display_order" integer NOT NULL,
"is_default" bool NOT NULL
)
and here is the relevant part of the settings.py file:
USE_SHORT_LANGUAGE_CODES = True
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en'
LANGUAGES = (('fr','Français'),
('ar','Arabe'),
('tr','Turk'),
('en','English'),
('nl','Dutch'),
('de','German'),
)
So there are 6 copies of the internationalized field "description" one for
each language. but it look like the name has not been suffixed by the
language code.
Can you tell me what I did wrong or if there is a workaround ?
Also I noticed that we are advised to use lazy foreign key but I don't now
what it is and doesn't understand it even after searching that term on
google.
Could you please explain it to me with an example ?
Best regards,
Frédéric Roland
Abdelmalek
frederic.roland@creativeconvergence.be
@rolandf
Very strange what you are experiencing. It is clear that the field is
internationalized because multiple versions of description are generated.
It is VERY weird though that all get the same name. If anything went wrong
they should at least be named 'description_' instead of 'description'.
Please try and verify that this problem goes away if you use django 1.3.1
instead of trunk. Easymode will be updated with fixes for this problem as
soon as 1.4 will be released. (Maybe some time before because you pointed
out an incompatibility).
Are you forced to use trunk?
Lazy foreign keys is when you set the pointed to class with a model id
(string) instead of a class:
class Foo(models.Model):
bar = models.ForeignKey('somepackage.Bar')
This way you don't have to import the model Bar from somepackage, which
can lead to problems because of circular imports.
I will update the documentation to include an example of the lazy foreign key.
Thank you for reporting these issues.
Kind regards
Lars van de Kerkhof
On 9 okt. 2011, at 23:35, Frédéric Roland wrote:
> Hello,
> I'm making a reference data model and I'd like to internationalize the
description field of my model but unfortunatelly it doesn't work with
django trunk.
> Here is the model:
>
> @I18n('description')
> class ReferenceDataValue(ModelAccounting):
> domain = models.ForeignKey('ReferenceDataDomain',related_name='values')
> code = models.CharField(max_length=10)
> description = models.CharField(max_length=255)
> parent = models.ForeignKey('self', related_name='child', blank=True,
null=True)
> display_order = models.IntegerField(default=0)
> is_default = models.BooleanField()
> links = models.ManyToManyField('self', through='ReferenceDataLink',
symmetrical=False, related_name = 'linked_value', blank=True, null=True)
>
> def __unicode__(self):
> return self.description
>
> and here is the generated sql:
>
> CREATE TABLE "ReferenceData_referencedatavalue" (
> "id" integer NOT NULL PRIMARY KEY,
> "is_deleted" bool NOT NULL,
> "created_at" datetime NOT NULL,
> "modified_at" datetime NOT NULL,
> "created_by_id" integer NOT NULL REFERENCES "auth_user" ("id"),
> "modified_by_id" integer NOT NULL REFERENCES "auth_user" ("id"),
> "domain_id" integer NOT NULL REFERENCES
"ReferenceData_referencedatadomain" ("id"),
> "code" varchar(10) NOT NULL,
> "description" varchar(255),
> "description" varchar(255),
> "description" varchar(255),
> "description" varchar(255),
> "description" varchar(255),
> "description" varchar(255),
> "parent_id" integer,
> "display_order" integer NOT NULL,
> "is_default" bool NOT NULL
> )
>
> and here is the relevant part of the settings.py file:
>
> USE_SHORT_LANGUAGE_CODES = True
>
> # Language code for this installation. All choices can be found here:
> # http://www.i18nguy.com/unicode/language-identifiers.html
> LANGUAGE_CODE = 'en'
>
> LANGUAGES = (('fr','Français'),
> ('ar','Arabe'),
> ('tr','Turk'),
> ('en','English'),
> ('nl','Dutch'),
> ('de','German'),
> )
>
> So there are 6 copies of the internationalized field "description" one
for each language. but it look like the name has not been suffixed by the
language code.
>
> Can you tell me what I did wrong or if there is a workaround ?
>
> Also I noticed that we are advised to use lazy foreign key but I don't
now what it is and doesn't understand it even after searching that term on
google.
> Could you please explain it to me with an example ?
>
> Best regards,
> Frédéric Roland
>
>
> Abdelmalek
> frederic.roland@creativeconvergence.be
> @rolandf
>
>
>
PermanentMarkers
kvk 09170823
tel 026-3704887
mob 06-24352007
specialunderwear@gmail.com
lars@permanentmarkers.nl
Hi Lars, With 1.3.1 it was ok, I switched to Django trunk because you can make the ordering dynamic. My I idea was to sort the records on the field related to the language of the current user. ModelAdmin can have a get_ordering() method that I wanted to use. Also the database I use for development is sqlite I don't know if it could explain the bug. Thank you for your explanation about Lazy foreign keys. I can provide you more information to help debug that issue if needed. Regards, Frédéric Le 10 oct. 2011 à 00:29, Lars van de Kerkhof a écrit : > Very strange what you are experiencing. It is clear that the field is internationalized because multiple versions of description are generated. It is VERY weird though that all get the same name. If anything went wrong they should at least be named 'description_' instead of 'description'. > > Please try and verify that this problem goes away if you use django 1.3.1 instead of trunk. Easymode will be updated with fixes for this problem as soon as 1.4 will be released. (Maybe some time before because you pointed out an incompatibility). > > Are you forced to use trunk? > > Lazy foreign keys is when you set the pointed to class with a model id (string) instead of a class: > > class Foo(models.Model): > bar = models.ForeignKey('somepackage.Bar') > > This way you don't have to import the model Bar from somepackage, which can lead to problems because of circular imports. > I will update the documentation to include an example of the lazy foreign key. > > Thank you for reporting these issues. > > Kind regards > > Lars van de Kerkhof > > On 9 okt. 2011, at 23:35, Frédéric Roland wrote: > >> Hello, >> I'm making a reference data model and I'd like to internationalize the description field of my model but unfortunatelly it doesn't work with django trunk. >> Here is the model: >> >> @I18n('description') >> class ReferenceDataValue(ModelAccounting): >> domain = models.ForeignKey('ReferenceDataDomain',related_name='values') >> code = models.CharField(max_length=10) >> description = models.CharField(max_length=255) >> parent = models.ForeignKey('self', related_name='child', blank=True, null=True) >> display_order = models.IntegerField(default=0) >> is_default = models.BooleanField() >> links = models.ManyToManyField('self', through='ReferenceDataLink', symmetrical=False, related_name = 'linked_value', blank=True, null=True) >> >> def __unicode__(self): >> return self.description >> >> and here is the generated sql: >> >> CREATE TABLE "ReferenceData_referencedatavalue" ( >> "id" integer NOT NULL PRIMARY KEY, >> "is_deleted" bool NOT NULL, >> "created_at" datetime NOT NULL, >> "modified_at" datetime NOT NULL, >> "created_by_id" integer NOT NULL REFERENCES "auth_user" ("id"), >> "modified_by_id" integer NOT NULL REFERENCES "auth_user" ("id"), >> "domain_id" integer NOT NULL REFERENCES "ReferenceData_referencedatadomain" ("id"), >> "code" varchar(10) NOT NULL, >> "description" varchar(255), >> "description" varchar(255), >> "description" varchar(255), >> "description" varchar(255), >> "description" varchar(255), >> "description" varchar(255), >> "parent_id" integer, >> "display_order" integer NOT NULL, >> "is_default" bool NOT NULL >> ) >> >> and here is the relevant part of the settings.py file: >> >> USE_SHORT_LANGUAGE_CODES = True >> >> # Language code for this installation. All choices can be found here: >> # http://www.i18nguy.com/unicode/language-identifiers.html >> LANGUAGE_CODE = 'en' >> >> LANGUAGES = (('fr','Français'), >> ('ar','Arabe'), >> ('tr','Turk'), >> ('en','English'), >> ('nl','Dutch'), >> ('de','German'), >> ) >> >> So there are 6 copies of the internationalized field "description" one for each language. but it look like the name has not been suffixed by the language code. >> >> Can you tell me what I did wrong or if there is a workaround ? >> >> Also I noticed that we are advised to use lazy foreign key but I don't now what it is and doesn't understand it even after searching that term on google. >> Could you please explain it to me with an example ? >> >> Best regards, >> Frédéric Roland >> >> >> Abdelmalek >> frederic.roland@creativeconvergence.be >> @rolandf >> >> >> > > PermanentMarkers > kvk 09170823 > tel 026-3704887 > mob 06-24352007 > specialunderwear@gmail.com > lars@permanentmarkers.nl > > > >