As I'm thinking about sweeping changes anyway I wanted to share another
idea I've been having.
While looking for a nice admin solution I thought about the ordering of
fields. At the moment any translatable fields are put at the bottom of
the change view. This is a consequence of using inline fieldsets. When
DM has its own real admin form we can think about interspersing
translatable fields with normal fields. That got me thinking about the
models themselves.
Because translatable fields are defined in their own inner class they
always come last in the field order. Of course you can override the
ordering in the ModelAdmin class, but why shouldn't DM work like this:
class Article(models.Model) [or TranslatableModel?]
title = ...
contents = ...
category = ...
creator = ...
created = ...
class Meta:
multilingual_fields = ('title', 'contents')
I feel this is a more intuitive interface. It preserves order and
integrates nicely with other model options. On the other hand, if we are
going to move in the direction of going less implicitly (or to put it
another way: around the back of the user) a Translation class would be
better.
How do the rest of you feel about this?
Regards,
Joost
--
Joost Cassee
http://joost.cassee.net
The syntax I had proposed was this:
class MyModel(models.Model):
name = models.CharField(max_length=25, multilingual=True)
desc = models.TextField(blank=True, multilingual=True)
creation_date = models.DateTimeField(...)
In my eyes, this would be ideal, no inner classes, no anything.
The ordering etc, should be handled at the admin model class in NFA.
--
Panos Laganakos
> A while back I discussed a different syntax with Michael Trier, and we
> had agreed it, that it looked nice and clean.
>
> The syntax I had proposed was this:
>
> class MyModel(models.Model):
> name = models.CharField(max_length=25, multilingual=True)
> desc = models.TextField(blank=True, multilingual=True)
> creation_date = models.DateTimeField(...)
>
>
> In my eyes, this would be ideal, no inner classes, no anything.
Agreed, this looks even nicer.
I was thinking about a solution that would require no monkey patching.
Fabio mentioned that reducing the feature set (lose 'name_en') would
remove the need to monkey patch the query mechanism. I think that if we
require models with translatable fields to extend some MultilingualModel
class we could pick pick out the fields with multilingual=True before
the Django Model class gets its hands on them. That way we could leave
the original Model.__new__ alone. If DM becomes part of Django proper
the code in MultilingualModel can be folded into Model.
If there are no conceptual objections with this approach I can whip up a
proof of concept.
> The ordering etc, should be handled at the admin model class in NFA.
Sure, but it is just so convenient to have fields in 'standard order' in
the model itself.
Even if the feature set would be reduced we'd still need to copy and
modify the Query methods in our subclass to support ordering;
I'm trying to find out if a simpler patch for Django could allow to
avoid this, however once 1.0 is out the Query code should not change
that much.
I think that in order to avoid monkey patching it would be necessary
to create a base MultilingualModel class as you proposed earlier in
the list;
given the current rate of brainstorming, maybe a branch would be the
best place for proof of concepts.
Best,
Fabio Corneti
in...@corneti.com
>
> Ok what about difrent solution?
> instead of creating Translation tables why not to add extra (dynamic)
> colls
>
> installing aditional languages would require ALTER command.
> + Imho this solution would be much more faster due to lack of JOINS
> + ingerention with admin would be easyier
There are some issues which need to be considered (and probably have
been already considered by Marcin):
1) If you have to change the type of a field, you need to issue alter
column commands for each language column
2) Some databases put a limit on the absolute number of columns in a
table or on the number of columns of a particular type
3) If you are dealing with Text fields and have many languages or many
fields, you could end up with really large records, which
is usually bad for performance
Best,
Fabio Corneti
in...@corneti.com
--
Panos Laganakos
while this is our app :), I think we should ask the Django devs that
are looking into i18n stuff, to get on this topic too.
We can do whatever feels right to DM devs/users, but if we're aiming
of being closer or integrate with Django at one point, it will be
easier to have them on board from this point.
--
Panos Laganakos
I liked this syntax (and that's all it is: different syntax) because 1)
it allow default field ordering and 2) looks like other meta options.
> Panos Laganakos wrote:
>> class MyModel(models.Model):
>> name = models.CharField(max_length=25, multilingual=True)
>
> This requires some monkey patching: you have to modify
> Field.__init__. ModelBase.__new__ happens too late -- it has no way
> of intercepting the multilingual parameter before CharField.__init__
> chokes on it.
>
> Also, adding parameters to __init__ feels more implicit and "magical"
> to me than marking multilingual fields from the outside, like using a
> block or the Meta.multilingual_fields list.
This syntax feels even neater. If DM would be integrated with Django
proper this solution would neatly fold into the Field class.
In general I agree that a Translation inner class conveys that fact that
you're dealing with special cases better. To put it another way: DM must
work pretty transparently if we want to 'earn' less intrusive syntax.
And of course it should really be better to justify backward compatibility.
> yml wrote:
>> I would introduce a new field rather than modifying the
>> existing "CharField" let us say "MultilingualCharField".
>
> This, in turn, limits the list of fields you can mark as multilingual
> to those which we provide and makes it difficult for people who want
> to make their custom fields multilingual.
Seconded.
> 2. storage
> ----------
>
> [...] If anyone wanted to experiment with remodeling DM to store data
> directly in the model table -- please do, in a branch, so that we can
> play with it and see if it works.
That would be great, but I think the whole DM code depends on the
storage paradigm. Wouldn't that mean rewriting pretty much everything
else too?
My intuition says that the normalized storage model is:
- more relational
- more flexible with languages
- faster on sparse data
- faster on larger records with more languages
... while the column model is:
- faster on fewer languages
- faster on dense data
- potentially simpler in implementation
We must keep in mind that we have not had any real tests. Maybe we
should focus on finding a good data set for testing? Anyone have one
lying around? :-)
> Is this full suport of django admin?
> I belive not, Translations will still be on the bottom,
> are you able to change the order of Translated fields?
Certainly not, the admin still uses inlines. I'm looking into new ways
of doing the admin. My current thinking veers towards using a custom
MultilingualModelAdmin that overrides get_form() and save().
As for layout, I thought it would be cool to have a small javascript
dropdown selection box that selects the language being edited. (The
project django-i18ndynamic had something similar.) A non-javascript
back-up layout would look a bit like the current layout, but with field
ordering. That would probably look a bit ugly, though.
I am interested in any other admin layout ideas you may have.
> I think that having separate Translation class is better becouse we
> can do this :
>
> class MyOtherModelInline(admin.StackedInline):
> template = 'my_new_template_tabular.html'
Maybe I don't understand you correctly, but I thought the example in
articles/admin.py shows that this can be done. You just define a
Translation(TranslationModelAdmin) inner class. I just tried
formfield_for_dbfield() but any ModelAdmin feature should work.
> oh and about the [...] /articles/admin.py, search_fields does not
> work ;]
Right! :-) I don't think anyone will fix bugs in the current admin code,
though.
> I mean, can you define template for translation inner class ? (edit
> inline template)
Should work, try it? (If it doesn't work and the fix takes too much time
I will solve the problem in the new admin templates, though.)
--
Panos Laganakos