views:

38

answers:

1

I have a model that is something like this:

class ReturnAuthorization(models.Model):
    custom_id = models.CharField(max_length=40)

class RMAAPILog(models.Model):
    return_authorization = models.ForeignKey(ReturnAuthorization)

If I were to delete() a return authorization, I can't have it delete all the RMAAPILog()s that are related to it. In this case they get deleted. There can be many attempts to get an RMA from the outside API (so many RMAAPILog()s per ReturnAuthorization(), but there can only be one ReturnAuthorization() for each RMAAPILog() of course because it's a log of an attempt to authorize a specific ReturnAuthorization(). What would be the better way to do this, or am I thinking of it all wrong?

+1  A: 

Related SO question: How do I create a Django model with ForeignKeys which does not cascade deletes to its children?

Tom
Oops, That's not right. That post is about a guy having the opposite problem. He has a model that he needs this cascading on but it isn't working. I need the opposite effect. I need to delete the parent without the child being deleted.
orokusaki
Sorry, I couldn't tell if that matched or not. Doesn't one of the answers apply though? "Django's ForeignKey manager has a method called clear() that removes all objects from the related object set. Calling that first, then deleting your object should work." - http://stackoverflow.com/questions/1006135/how-do-i-create-a-django-model-with-foreignkeys-which-does-not-cascade-deletes-to/1007778#1007778
Tom
There is a patch in http://code.djangoproject.com/ticket/7539 to add support for controlling ON DELETE behavior in the model.
Tom
Sweet, that patch is what I'm looking for. Thanks.
orokusaki