Change the foreignKey id to another Field

I don’t know if there is a logic for this, because i seen it before when I programed with C# and VB, but in Django, it’s seems hard to get it.

So what I want to ? I want the table in database save the name and not the id of the foreignKey. And this is the

from pyexpat import model
from statistics import mode
from venv import create
from django.db import models
from django.contrib.auth.models import User
from django.db.models.base import Model
from django.forms import IntegerField

class Post(models.Model):
    name = models.CharField(max_length=150)

    def __str__(self):
        return str(

class Person(models.Model):
    post = models.ForeignKey(Post , on_delete=models.CASCADE)
    name = models.CharField(max_length=100, unique=True)

    def __str__(self):
        return f"({} is {})"

class Room(models.Model):
    name = models.CharField(max_length= 150, unique = True)

    def __str__(self):
        return str(

class Classification(models.Model):
    name = models.ForeignKey(Person, on_delete=models.CASCADE)
    room = models.ForeignKey(Room, on_delete=models.CASCADE)
    date = models.DateField(auto_created=False)
    create_date = models.DateTimeField(auto_created=True)

    def __str__(self):
        return f"({} Take {}  at {})"

The result in Database table:

id problem 2

What I want to see in the database table, is that Django replace the id’s in name_id column with names, and room_id with room names

is that possible ?

Thank you

See Model field reference | Django documentation | Django
(Usually a bad idea in most cases, but Django won’t prevent you from making some mistakes.)

Do you mean Django preferd id then other field ?

As a general rule in database design, you want your foreign keys to reference the primary key of the object table. (This isn’t something that is specific to Django, it’s a principle of good relational data modelling.) That primary key is the identifier of that row, allowing for all other fields to be changed. By assigning a Foreign Key to a different field, you are, in effect, creating two separate identifiers for that row.

If you don’t want numeric IDs as the primary key, that’s acceptable as well - but then you still end up having the Foreign Key referencing the primary key of the target table.

Thank you verymuch for this,
All what I want that when using Pandas filtering, it’s show me names not ID’s , this is why I want to names shoing in the table, so when I filtering with Pandas, names showed and not ID’s
I was have an Idea, that Set the table with id’s, and trying to doing a lookup Method for each column of id’s (example, in Classification, in the room_id column , triung to lookup the ID’s with their room name, after that set Pandas Filtering)