replace id with other field in the views

Hello,
my question is:
How do I tell to Django to replace the Column type_id to the name field in the views (html page).

and here I have foreignkey, it gave me id (type_id), and this screentshot of fabrication class:

the column type_id is comming from the composant_type class,

models.py:

from django.db import models
from django.contrib.auth.models import User
from django.db.models.base import Model
from CentreCout.models import CentreCoutDB




class fiche(models.Model):
    centre_cout = models.CharField(max_length=150)
    number = models.CharField(max_length=100)
    name = models.CharField(max_length=100, unique=True)
    
    def __str__(self):
        return self.name
   
class unite(models.Model):
    name = models.CharField(max_length= 150, unique=True)

    def __str__(self):
        return self.name
    
    
class composant_type(models.Model):
    name = models.CharField(max_length=150, unique=True )

    def __str__(self):
        return f"({self.name})"

    
class composant_fab(models.Model):
    type = models.ForeignKey(composant_type, to_field='name',  on_delete=models.CASCADE)
    name = models.CharField(max_length=150, unique=True)

    def __str__(self):
        return f"({self.name})"
        


class fabrication(models.Model):
    grade = models.ForeignKey(fiche, to_field='name',on_delete=models.CASCADE)
    type = models.ForeignKey(composant_type, on_delete=models.CASCADE, blank=True, null=True)
    composant = models.ForeignKey(composant_fab , to_field='name', on_delete=models.CASCADE, null=True, blank=True)
    unite = models.ForeignKey(unite, to_field='name',on_delete=models.CASCADE)
    composant_value = models.FloatField(blank=True, null=True)
    
    def __str__(self):
        return f"({self.grade}-{self.composant}-{self.composant_value}-{self.unite})"

views.py

from django.shortcuts import get_object_or_404, render
from django import views
from django.http import HttpResponse
from .models import *
import pandas as pd



def fabrications(request):
  lesfichestab = fiche.objects.all()
  fabricationtab = fabrication.objects.all().values()
  df = pd.DataFrame(fabricationtab) 
  context = {
    'lesfichestab':lesfichestab,
    'fabricationtab':df.to_html()
  }

  return render(request,'fabrications/fabricationpage.html', context)

note : I use Pandas method, because i have to do some Feltring and pivoting of the table.
thank you

this is the answer, thank you

def fabrications(request):
  lesfichestab = fiche.objects.all()
  fabricationtab = fabrication.objects.all().values()
  df = pd.DataFrame.from_records(
    fabricationtab.values(
      "grade",
      "type__name",
      "composant",
      "unite",
      "composant_value"))

In Django, instances of Models are instances of Python classes. Foreign Key attributes are class instance references.

Example: Assume two classes Book and Author, where Book has a field (“attribute”) named author being a ForeignKey to Book. If you have an instance of book, then book.author is a reference to that instance of Author. If Author has a field (“attribute”) named name, then book.author.name is the name of the author of that book.

Review the docs at Templates | Django documentation | Django, Model field reference | Django documentation | Django and Making queries | Django documentation | Django

As a side note, I’ll mention that if there’s any “filtering” of the data that needs to be done, you’re better off doing it by writing your query to filter the data before you start processing it. You may also find it more perfomant to construct your query such that it returns the data in its “pivoted” format rather than passing it through to Pandas.

Hello Mr Ken
thank you very much, you gave a good lesson yesterday,
I tried to change the id column to another field, and export the database using ImportExport mothod, I saw that this operation gave me an Excel table with Id’s and not with name field (in my cas I want to change id with name field), so I understand what you sad,
and now, you gave the exact documentation of my second question : what If I didn"t use Pandas, how can I tell Django to change id with other Field ? so you give the answer

I make me feel very happy, I wish become like you