0
我已经创建了下面的M2M表中介模型M2M入门 -删除与中介模式
class Position(models.Model):
position = models.CharField(max_length=100)
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
positions = models.ManyToManyField(Position, through ='Timestamp', blank=True, null=True)
class Timestamp(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
position = models.ForeignKey(Position)
userprofile = models.ForeignKey(UserProfile)
我创建了以下条目至今 -
>>> entry1 = Timestamp(userprofile=userprofile, position=position1)
>>> entry2 = Timestamp(userprofile=userprofile, position=position2)
现在我必须在userprofile_timestamp
表
-- profile & position1
-- profile & position2
两个项目我将如何删除profile & position1
入口?在文档(https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships)中,它提到使用profile.positions.clear()
清除所有条目,但我将如何删除单个条目?谢谢。