我正在将我的Web应用程序移动到Django 1.7,我有一个非常好奇的错误,也许你们中的一个人知道正在发生.
class Product(models.Model):
title = models.CharField(max_lenght=100)
slug = models.SlugField()
content = models.TextField()
class Gallery(models.Model):
product = models.ForeignKey(Product, related_name="images")
original = models.ImageField()
class MyView(DetailView):
model = Product
def get_context_data(self, **kwargs):
....
# My error is here, when use this context and parse template
context["galleries"] = Product.images.all()
Run Code Online (Sandbox Code Playgroud)
给以下错误消息:
'ForeignRelatedObjectsDescriptor' object has no attribute 'all'
response = wrapped_callback(request, *callback_args, **callback_kwargs)
Run Code Online (Sandbox Code Playgroud)
Ale*_*lex 12
尝试:
context["galleries"] = self.object.images.all()
Run Code Online (Sandbox Code Playgroud)
您需要在Product模型的特定实例上调用它,该实例应该是您的对象.