2013-03-08 44 views
1

如何取消鏈接泛型關係?Django:如何取消鏈接泛型關係?

我想解除註釋和客戶的關聯。

models.py

class Note(models.Model): 
    contents = models.TextField() 

    content_type = models.ForeignKey(ContentType) 
    object_id = models.PositiveIntegerField() 
    content_object = generic.GenericForeignKey('content_type', 'object_id') 


class Customer(models.Model): 
    name = models.CharField(max_length=50, unique=True,) 
    notes = generic.GenericRelation(Note, null=True) 

>>> cs=Customer.objects.get(pk=1)
>>> cs.notes.all()[0].delete()

cs.notes.all()[0]被完全刪除。

我不想完全刪除。我只想取消鏈接...

我該怎麼辦?

回答

0

唯一的「鏈接」存在於Note對象的content_typeobject_id指的是Customer實例。所以,改變這些,鏈接就會消失。

+0

你能給我一個示例代碼...? – chobo 2013-03-08 12:28:11