#9501: Generic relations to derived models won't allow for deletion of objects
those models are attached to.
--------------------------+-------------------------------------------------
 Reporter:  Beetle_B      |       Owner:  nobody    
   Status:  new           |   Milestone:            
Component:  Contrib apps  |     Version:  1.0       
 Keywords:                |       Stage:  Unreviewed
Has_patch:  0             |  
--------------------------+-------------------------------------------------
 OK. Here's my scenario. I'm working with a blog, and with a comments app.

 Let's say the comment's model is Comment. As it can be attached to any
 object, it has a generic foreign key to ContentType:

 {{{
     # Generic Foreign Key Fields
     content_type = models.ForeignKey(ContentType)
     object_id = models.PositiveIntegerField(_('object ID'))
     content_object = generic.GenericForeignKey()
 }}}

 Now I didn't like the Comment model: It was lacking an important field
 (comment_html). I didn't want to touch the comment's app's source code. So
 I created a new model that inherited from Comment and called it
 CommentMod. It consists of simply the extra field and overrides the save
 method.

 The blog app has an Entry model. In that model, I put:

 {{{
     comments = GenericRelation(CommentMod)
 }}}

 The goal was that if I delete a blog entry, it should delete all comments
 associated with it.

 However, when I try to delete a blog entry that has comments via the
 admin, I get an error. Upon observing the SQL, it turns out that it can't
 find an 'object_id' and 'content_type_id' columns in the CommentMod
 tables.

 It can't do that because it's a derived model. Those columns are in the
 Comment tables.

 I tried changing it to:

 {{{
     comments = GenericRelation(Comment)
 }}}

 But then if I try to delete Entry, I get a foreign key constraint problem
 from the DB (MySQL).

 So it seems that I can't expect generic relations to work with derived
 models. I don't know if this is by design - if it's not, then it's a bug.

 For now, I'll just create a GenericForeignKey in the derived models as
 well. Not sure if it will work...

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9501>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to