Re: multi-table inheritance and modification of OneToOneField options
On Fri, 2009-08-07 at 00:30 -0700, Jan Ostrochovsky wrote: > Thank you, Malcolm. > > In fact, our current design was, as you recommended: > > Subject ---one-to-one-null-false--- Address ---one-to-one-null-true--- > Payment (Invoice) > > I want to use generic views and to join Subject+Address in the same > form, and model inheritance seemed to me as most straightforward > solution for this need, but as you do not recommend it, Bear in mind that there might be somebody who gives stricter recommendations on not abusing model inheritance around here, but I'm not sure who they would be. I very much view it as a Python equivalent (with some abstraction leakage from DB -> Python), but my view isn't universally held. In this case, though, what you're asking for isn't possible in the way the code is implemented, so it's not just a matter of preference. > I will look > for another solution... e.g. form inheritance, as I found it here > http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#form-inheritance > or here http://www.djangosnippets.org/snippets/703/. Hmm ... if you're doing this for the form result and you aren't intermixing the fields from Subject and Address (or even if you are), you might be better served by still making each on its own ModelForm and just passing both into the template. Then layout both Django forms inside a single HTML form element. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: multi-table inheritance and modification of OneToOneField options
Thank you, Malcolm. In fact, our current design was, as you recommended: Subject ---one-to-one-null-false--- Address ---one-to-one-null-true--- Payment (Invoice) I want to use generic views and to join Subject+Address in the same form, and model inheritance seemed to me as most straightforward solution for this need, but as you do not recommend it, I will look for another solution... e.g. form inheritance, as I found it here http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#form-inheritance or here http://www.djangosnippets.org/snippets/703/. Jano On Aug 7, 3:50 am, Malcolm Tredinnick wrote: > On Thu, 2009-08-06 at 07:15 -0700, Jan Ostrochovsky wrote: > > Hello, > > >http://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-in... > > says: > > The inheritance relationship introduces links between the child model > > and each of its parents (via an automatically-created OneToOneField). > > >http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield > > says: Multi-table inheritance is implemented by adding an implicit one- > > to-one relation from the child model to the parent model... > > > The question is: how can I set options of that implicit OneToOneField? > > Most interesting is null=True / null=False. > > You don't. Model inheritance is a Python-level thing and things like > "optional" inheritance doesn't existence for Python inheritance. It's a > shortcut for emulating Python class inheritance as much as possible. > > If you want this level of control, model the relations explicitly and > set the options on the OneToOneField to whatever you like. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: multi-table inheritance and modification of OneToOneField options
On Thu, 2009-08-06 at 07:15 -0700, Jan Ostrochovsky wrote: > Hello, > > http://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance > says: > The inheritance relationship introduces links between the child model > and each of its parents (via an automatically-created OneToOneField). > > http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield > says: Multi-table inheritance is implemented by adding an implicit one- > to-one relation from the child model to the parent model... > > The question is: how can I set options of that implicit OneToOneField? > Most interesting is null=True / null=False. You don't. Model inheritance is a Python-level thing and things like "optional" inheritance doesn't existence for Python inheritance. It's a shortcut for emulating Python class inheritance as much as possible. If you want this level of control, model the relations explicitly and set the options on the OneToOneField to whatever you like. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
multi-table inheritance and modification of OneToOneField options
Hello, http://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance says: The inheritance relationship introduces links between the child model and each of its parents (via an automatically-created OneToOneField). http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield says: Multi-table inheritance is implemented by adding an implicit one- to-one relation from the child model to the parent model... The question is: how can I set options of that implicit OneToOneField? Most interesting is null=True / null=False. (I want to "inherit" to one class optionally (Invoice Address) and to one class it is required (Residence Address). Base class is Address.) Thanks in advance. Jan Ostrochovsky --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---