最佳答案
我尝试在另一个模型中获取模型对象实例,我提出了这个错误:
Manager isn't accessible via topic instance
这是我的模型:
class forum(models.Model):
# Some attributs
class topic(models.Model):
# Some attributs
class post(models.Model):
# Some attributs
def delete(self):
forum = self.topic.forum
super(post, self).delete()
forum.topic_count = topic.objects.filter(forum = forum).count()
以下是我的观点:
def test(request, post_id):
post = topic.objects.get(id = int(topic_id))
post.delete()
然后我得到了:
post.delete()
forum.topic_count = topic.objects.filter(forum = forum).count()
Manager isn't accessible via topic instances