Django get Foreign key - multiple image

What you’re not doing with this set of code is associating the specific projeler2 with the individual instances of projeler1. The select_related clause probably isn’t doing what you think it’s doing. You’ll find that you’re better off by changing it to:

def projeisleri(request):
    projeler1 = Proje_Isleri.objects.all().prefetch_related('proje_isleri_resim_set')

In your template, your first for loop, proje1 is an individual projeler1. Each of the related instances of Proje_Isleri_Resim can then be iterated over as:
{% for foo in proje1.proje_isleri_resim_set %}
(See the Following relationships “backwards” section of the docs.)

At this point, each foo is an individual instance of Proje_Isleri_Resim, so the image field would be referenced as foo.Proje_Resim.

Couple of style notes I would recommend:

  1. Use lower-case names for fields, not capitalized names
  2. In your context, name your entries as plurals when they represent something to be iterated over.
  3. Try to find a more descriptive name for your variables instead of “projeler1” and “projeler2”, especially when they refer to two different classes.
1 Like