2010/12/20 Łukasz Rekucki <lreku...@gmail.com>: > On 21 December 2010 00:18, Morgan Wahl <morgy.w...@gmail.com> wrote: >> Actually, it's funny you mention #7623; my situation _is_ described in >> #11618 ( http://code.djangoproject.com/ticket/11618 ). That bug was >> marked as a dup of #7623, but in my opinion isn't. > > It is a duplicate, that's why I mentioned #7623 which is tracking this > bug. Existence of another table is irrelevant here, IMHO. The main > scheme is the same: You have an instance of class A and you want to > create an instance of class B which is a subclass of A, by writing: > > a = A.object.get(pk=1) # existing instance of A > b = B(parent=A) > b.save() # this will fail > > The patch on #7623 is describing exactly this situation, so you should > check it out. > Actually, the code you give doesn't fail. It merely overwrites the fields in 'a' with the ones given on 'b's instantiation. Which is not quite what I expected, but does make sense now that I think about it (since when you save a new instance, you don't leave any field _unspecified_, it's just that some fields have defaults so you don't have to mention their values).
#7623's description is something a bit more broad. In terms of your example, if C is also a subclass of A and b an instance of B, it's proposing c = C(parent=b) presumably the resulting 'c' instance would have all the fields of A and C and it would share it's A and fields with the 'b' instance. Thus if A has a string field called 'name' and you do: c.name = 'someting a rather' It would effectively set b.name as well (since they would both be backed by the same row in the table corresponding to A). This is not how class inheritance typically behaves, and I think it breaks the analogy Django's ORM makes between it's tables in the database and Python objects. (Now that I think about my example may have as well, just a bit more subtly.) >> >> 2010/12/20 Łukasz Rekucki <lreku...@gmail.com>: >>> This looks a lot like this bug: http://code.djangoproject.com/ticket/7623. >>> -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.