Hello Sebastien,
I'll answer your questions in reverse order, for the sake of simplicity :)
2) display fields of the subclass in the list. there are some simple ways to do this :
- simply define a property with the same name on all subclasses, and display
this property (then the calculation of the property is done in Python)
- use a columnproperty that selects the requested field from the related table
(have a look at Party.full_name in camelot.model.party to have an idea on
how this works)
1) There is a reason why the form of Item is used, that is because when
a form is opened, you can browse through the complete list with page up/down.
If the items in the list are of different types, the form should switch between
the Book or the DVD form, which would result in visual 'flicker' from the point of
view of the user.
Possible changes you can make to change this behavior :
1) When the user opens a form, the EntityAdmin.list_action action is triggered.
By default, this is the OpenFormView action. Another action could be triggered
that opens the form of the subclass.
2) Modify the form of the Item to include the fields of both DVD and Book, and modify
Item to have placeholders for all those fields. Then depending on the exact
subclass being displayed, certain fields can be enabled/disabled.
Please notice that joined table inheritance is a neat way of mapping OO design
techniques to a database, but one has to be careful when using it. It has
performance implications at the database level, and makes the ORM more
complex. So I would advice to use it only if when it is 100% sure it is the best
solution, and other techniques have been considered, such as a relational approach
or using 'types' or 'categories'.
Best regards,
Erik
On Fri, Apr 19, 2013 at 6:24 AM, Sébastien de Menten
<sdem...@gmail.com> wrote:
Hello,
I have a model that uses joined table inheritance. The model is hi-level the following:
Order = some specific fields + item list
Item = some specific fields + link to order
Book(Item) = an item with some additional specific fields to books
DVD(Item) = an item with some additional specific fields to DVDs
I have set EntityAdmin for each of the 4 classes, with the EntityAdmin for Book and DVD inheriting from the Item EntityAdmin.
In the application, when i show the form for the Order, i see all the items attached to the Order (be them Books or DVDs) as a list_display using the EntityAdmin of the Item class, which sounds perfectly fine. However, when i open the form for an Item, I do not see the Form for the specific class Book or DVD but stay with the Form of the Item.
My questions are twofold:
- how can Camelot display the form that is the more specific to the object when the object has a joined table inheritance (but I do not think that the joined table part is important, it is more the fact that there is polymorphism from the inheritance) ?
sebastien
--
--
You received this message because you are subscribed to the "Project Camelot" group.
Visit www.python-camelot.com for more information
To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-camel...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-camelot?hl=en
---
You received this message because you are subscribed to the Google Groups "Project Camelot" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-camel...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.