On 7 joulu, 16:18, Krzysztof Jurewicz <krzysztof.jurew...@gmail.com> wrote: > On 29.10.2012 14:34, Krzysztof Jurewicz wrote: > > > In February, Craig de Stigter released django-typed-models > > <https://groups.google.com/d/topic/django-users/63z-ejUQ1Eg/discussion>, > > a package implementing inheritance hierarchy for Proxy models with > > automatic type recasting. I've written a fork of it with additional > > possibility of adding fields to subclasses, therefore achieving a single > > table inheritance implementation similar to Ruby on Rails' STI. > > Refreshing this thread because it looks like my fork stopped working > properly with recent Django master. I suspect that commit c2e1e by Anssi > K ri inen should be blamed for this, especially the line > > # Skip all proxy to the root proxied model > opts = opts.concrete_model._meta > > in get_default_columns method. This causes it to generate potentially > invalid set of columns for instantiated model because children typed > models are implemented as proxy models and they have different set of > fields than the root model, which stores all fields from its subclasses. > In general having richer set of columns than required wouldn't be a > problem, but those columns are used as positional arguments in model > constructor and are therefore mapped incorrectly. > > I know that proxy models are intended to have the same set of fields as > the root model and that I was relying on a completely internal > implementation detail, so it has no chance of being treated as a bug, > but that being said, I wonder if maybe Django could be changed to make > such modifications easier. Currently I see the following solutions to > the encountered problem: > > 1. Do not touch Django code directly and adjust django-typed-models to > the changes made. This would probably require writing custom Manager > class for TypedModel with custom QuerySet class which will use custom > Query class with custom SQLCompiler class which will finally have > get_default_columns method copy-paste-changed. Not an elegant solution. > > 2. Take a completely different approach to achieve single table > inheritance ideas are welcome. > > 3. Modify Django code to be more friendly to django-typed-models. > Current behavior of SQLCompiler looks a bit hackish to me, because in > ideal world get_default_columns shouldn't care if a model is proxy or > not this should be handled by model class internally. So perhaps > another layer of abstraction could be added to Django ORM to allow > internal handling of such special cases as proxy models. This would > ideally allow to specify STI as a completely different model type than > proxy model. > > 4. Add single table inheritance as a new inheritance type in Django. > > I'm not very familiar with Django ORM internals and additionally I don't > know which of the above solutions have chances of getting approval by > core devs, so feedback is welcome.
Would a model._meta.get_default_columns() work for you? While this would still be internal API, it would be hopefully less likely to change in ways that require extensive rewrites to 3rd party apps. - Anssi -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.