'RelatedManager' object has no attribute 'hangiMateryaleIslemYapR'

Hello everyone, first of all my English is not very good and I apologize to everyone for this.

I have three models and all three of them are interconnected. The url named PaketAc works, but the url named imajAl does not work.

Since the for loop on the tutanaklar.html page creates a slug to the model named DosyaBilgileri, the url named imajAlma does not work. This is my idea.

however, I also need to access the fields of the model named IslemYapModel. I used related_name but it didn’t work. I have no idea how to do it. Thank you in advance for your help.


class DosyaBilgileri(models.Model):

    sahisKonumu = models.CharField(max_length=30, choices=SUPHELIKONUMU,  verbose_name='Şahıs Konumu', blank=True, null=True)

    sahisAdi = models.CharField(max_length=30, verbose_name='Şahıs Adı', blank=True, null=True)

    geldigiYer = models.CharField(max_length=75, verbose_name='Geldiği Birim', blank=True, null=True)

    geldigiSayi = models.CharField(max_length=25, verbose_name='Geldiği Sayı', blank=True, null=True)

    gelisTarihi = models.DateTimeField(auto_now_add=True, blank=True, null=True)

    rafNumarasi = models.CharField(max_length=50, verbose_name='Raf Numarası', blank=True, null=True)

    teslimYeri = models.CharField(max_length=70, verbose_name='Teslim Yeri', blank=True, null=True)

    userModeliBaglanti = models.ForeignKey(User, on_delete=models.CASCADE, related_name='dosyayaEkleyenKimR', blank=True, null=True)

    slug = AutoSlugField(populate_from='sahisAdi', unique=True, blank=True, null=True)



    def __str__(self):

        return self.sahisAdi + ' | ' + self.geldigiSayi

    class Meta:

        verbose_name_plural = 'Dosya Bilgileri'

        verbose_name = 'Dosya Bilgisi'


class MateryalEkle(models.Model):

    dosyaBilgileriBaglanti = models.ForeignKey(DosyaBilgileri, on_delete=models.CASCADE, related_name='hangiDosyayaMateryalEkleR', blank=True, null=True)

    materyalMarka = models.CharField(max_length=25, verbose_name='MATERYAL MARKA', blank=True, null=True)

    seriImei = models.CharField(max_length=25, verbose_name='MATERYAL SERI / IMEI / ICCID', blank=True, null=True)

    cinsi = models.CharField(max_length=25, verbose_name='MATERYAL CİNSİ', blank=True, null=True)

    bilgiNotu = models.CharField(max_length=200, verbose_name='MATERYALE AİT BİLGİ NOTU', blank=True, null=True)

    userModeliBaglanti = models.ForeignKey(User, on_delete=models.CASCADE, related_name='materyalleri', blank=True, null=True)

    slug = AutoSlugField(populate_from='materyalMarka', unique=True, blank=True, null=True)


    def __str__(self):

        return self.dosyaBilgileriBaglanti.sahisAdi + ' | ' + self.materyalMarka + ' | ' + self.dosyaBilgileriBaglanti.geldigiSayi+ ' | ' + self.userModeliBaglanti.username


    class Meta:

        verbose_name_plural = 'Materyal Ekle'

        verbose_name = 'Materyal Ekle'

class IslemYapModel(models.Model):

    materyalEkleBaglanti = models.ForeignKey(MateryalEkle, on_delete=models.CASCADE, related_name='hangiMateryaleIslemYapR', blank=True, null=True)

    imajTuru = models.CharField(max_length=25, blank=True, null=True)

    imajBaslamaSaati = models.CharField(max_length=25, blank=True, null=True)

    imajBitisSaati = models.CharField(max_length=25, blank=True, null=True)

    imajYazilim = models.CharField(max_length=25, blank=True, null=True)

    exportYazilim = models.CharField(max_length=25, blank=True, null=True)

    bilgiNotu = models.CharField(max_length=200, blank=True, null=True)

    userModeliBaglanti = models.ForeignKey(User, on_delete=models.CASCADE, related_name='materyallere', blank=True, null=True)

    slug = AutoSlugField(populate_from='imajTuru', unique=True, blank=True, null=True)


    def __str__(self):

        return self.materyalEkleBaglanti.materyalMarka + ' | ' + self.materyalEkleBaglanti.dosyaBilgileriBaglanti.geldigiSayi +' | ' + self.materyalEkleBaglanti.dosyaBilgileriBaglanti.sahisAdi


    class Meta:

        verbose_name_plural = 'İşlem Yap'

        verbose_name = 'İşlem Yap'


def tutanaklar(request):

    dosyaBilgileriD = DosyaBilgileri.objects.all().order_by('-id')

    return render(request, 'delil/tutanaklar.html', {'dosyaBilgileriD':dosyaBilgileriD})

def paketAcma(request, slug):

    DosyaBilgileriModelTumVeriler = get_object_or_404(DosyaBilgileri, slug=slug)

    buDosyayaAitMateryaller = DosyaBilgileriModelTumVeriler.hangiDosyayaMateryalEkleR.all()

    return render(request, 'delil/paketAcma.html', { 'DosyaBilgileriModelTumVeriler':DosyaBilgileriModelTumVeriler,'buDosyayaAitMateryaller':buDosyayaAitMateryaller, })

def imajAlma(request, slug):

    DosyaBilgileriModelTumVeriler = get_object_or_404(DosyaBilgileri, slug=slug)

    buDosyayaAitMateryaller = DosyaBilgileriModelTumVeriler.hangiDosyayaMateryalEkleR.hangiMateryaleIslemYapR.all()

    return reversed (request, 'delil/imajAlma.html', { 'DosyaBilgileriModelTumVeriler':DosyaBilgileriModelTumVeriler,'buDosyayaAitMateryaller':buDosyayaAitMateryaller, })


urlpatterns = [

    path('tutanaklar', views.tutanaklar, name='tutanaklar'),

    path('paketAcma/<slug:slug>', views.paketAcma, name='paketAcma'),

    path('imajAlma/<slug:slug>', views.imajAlma, name='imajAlma'),



{% if dosyaBilgileriD %}

                    {% for tekil in dosyaBilgileriD %}


                        <td class="align-middle ufo60">

                            {% if tekil.durum == 'YENİ KAYIT' %}

                            <i class="fas fa-unlock-alt mr-1 text-primary ufo1"></i>

                            {% elif tekil.durum == 'İŞLEMDE' %}

                            <i class="fas fa-battery-half mr-1 text-warning ufo1"></i>

                            {% elif tekil.durum == 'İŞLEMSİZ İADE' %}

                            <i class="fas fa-times-circle mr-1 text-danger ufo1"></i>

                            {% elif tekil.durum == 'BÖLGEYE GÖNDERİLDİ' %}

                            <i class="fas fa-mail-bulk mr-1 text-secondary ufo1"></i>

                            {% elif tekil.durum == 'DAİRE BAŞ. GÖNDERİLDİ' %}

                            <i class="fas fa-mail-bulk mr-1 text-info ufo1"></i>

                            {% elif tekil.durum == 'TESLİM EDİLDİ' %}

                            <i class="fas fa-battery-full mr-1 text-default ufo1"></i>

                            {% endif %}



                        <td class="align-middle ufo60"><i class="fas fa-signature mr-1 text-primary"></i>{{tekil.sahisAdi}}</td>

                        <td class="align-middle ufo60"><i class="fas fa-truck-moving mr-1 text-primary"></i>{{tekil.geldigiYer}}</td>

                        <td class="align-middle ufo60"><i class="fas fa-sort-numeric-up-alt mr-1 text-primary"></i>{{tekil.geldigiSayi}}</td>

                        <td><a href="{% url 'paketAcma' slug=tekil.slug %} " type="button" class="btn btn-primary mt-3" >PEKET AÇMA </a></td>

                        <td><a href="{% url 'imajAlma' slug=tekil.slug %} " type="button" class="btn btn-primary mt-3" >İMAJ ALMA </a></td>


                    {% endfor %}

                    {% endif %}


        {% if buDosyayaAitMateryaller %}
        {% for tekil in buDosyayaAitMateryaller %}
        {% endfor %}
        {% endif %}

When you post code snippets here, please insert them between lines containing only 3 backticks - ```. (Make sure you use the backtick - ` and not the apostrophe - '.) That means you would have one line with the 3 backticks, your code, and then one more line with just the 3 backticks. That allows this forum software to format your code nicely:

# The line above this is just ```
def function(parm):
    return parm
# The line after this is just ```

If you want, you can edit your post to put the backticks before and after each of the code blocks you’ve posted - that’ll make it all easier for everyone to read.

(Also, and I don’t know if it’s an artifact of how you’ve posted the code, but the double-spacing within the code blocks makes it more difficult to visually understand the structure. It would also be helpful if the excess blank lines were removed.)

Looking for some clarification here:

What do you mean here? What precisely is not working?

Access those fields, where? What are you trying to do with them?

There’s no need for you to apologize for your English - you’re doing a lot better than I would ever be able to do in any other language.

But we are going to need a more detailed description of what the problems are, and what you’re trying to do, and the full error messages that you might be receiving.

Dear KenWhitesell,
thanks for your help. I solved my problem :slight_smile: