ForeignRelatedObjectsDescriptor 'has no attribute' all '

I am moving my web application to Django 1.7 and I have a very curious mistake, maybe one of you knows what is going on.

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 the following error message:

'ForeignRelatedObjectsDescriptor' object has no attribute 'all'
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
+4
source share
1 answer

Try:

context["galleries"] = self.object.images.all()

You want to call it on a specific instance of your model Product, which should be your object.

+12
source

Source: https://habr.com/ru/post/1538499/