Hi Andreas,
welcome back! :)
On 15 Jan 2016, at 12:29, Andreas Jung wrote:
> I have the following existing model (experimental, can be rearranged
> as needed)
>
>
https://gist.github.com/zopyx/5ae4fd53804ca7dd29ed
>
> which is working fine from pure Python.
>
> Q1: what is the best way for refactoring the model in way to make it
> usable within Kotti
>
> Using the model as mix-in does not work, something like
>
> class Country(Content, model.Country):
> .....
>
> In general I want to keep the defined relationships that are defined
> inside the mode in Kotti as well (need by Kotti related application
> logic and views).
Not entirely sure what you want to achieve, so the following might not
suit your need.
If I see it right, you only have 1:n relationships (country -> region ->
parish -> school -> student -> score). This can perfectly be managed
within Kotti's node tree. To make this work, you'd *only* inherit from
kotti.resources.Content, like this:
class Country(Content):
""" Managed through Kotti """
__tablename__ = 'regions'
id = Column(Integer(), ForeignKey(Content.id), primary_key=True)
title could be omitted from your models, as it would be inherited from
Content already.
kotti.resources.Node gives you the parent / children relationships (via
the parent_id attribute) which is what your model does, except that it
doesn't enforce that a country can *only* contain regions *on a database
level*. It can easily achieved on the application level though. Unless
you need the former, that'd be easiest.
> Q2: Kotti seems to derive the table name for a content-type from the
> class name + 's'.
> Is there a way to overwrite this (in particular because the plural of
> 'country' is 'countries' and not 'countrys'.
> In general my model defines the table name as part of the decl. layer.
Sure, Kotti's Base class has a declared_attr for __tablename__ (see
https://github.com/Kotti/Kotti/blob/master/kotti/sqla.py#L220),
overwriting that attribute in your derived classes should be sufficient.
HTH,
Andreas