Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'ForeignRelatedObjectsDescriptor' object has no attribute 'all'

Tags:

python

django

I'm moving my web application to Django 1.7 and I have a very curious mistake, perhaps one of you know is happening.

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()

Givin the following error message:

'ForeignRelatedObjectsDescriptor' object has no attribute 'all'
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
like image 677
Colpaisa Avatar asked Dec 15 '22 23:12

Colpaisa


1 Answers

Try:

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

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

like image 183
Alex Avatar answered Mar 24 '23 08:03

Alex