Showing Operation object (1) when trying to get foreignkey Django

I am trying to post a table in HTML and I get This "Operation object (1)" instead of just the id "1" How is possible to fix this

as you can see in the picture where is selected I want to have the id, not text models.py

class Operation(models.Model):
    operationID = models.IntegerField(primary_key=True)
    assignee = models.ForeignKey('Employee', on_delete=models.CASCADE)
    dateRegistered = models.DateTimeField(auto_now_add=True)
    timeStart = models.DateTimeField(auto_now_add=True, null=True)
    timeFinish = models.DateTimeField(null=True)
    status = models.ForeignKey(
        'Status', on_delete=models.CASCADE)

class Subtask(models.Model):
    subtaskID = models.IntegerField(primary_key=True, auto_created=True)
    operationID = models.ForeignKey('Operation', on_delete=models.CASCADE)
    containerID = models.CharField(max_length=255)
    containerWeightT = models.DecimalField(max_digits=6, decimal_places=2)
    loadSeq = models.IntegerField()
    moveTo = models.ForeignKey('MoveTo', on_delete=models.CASCADE)
    stow = models.ForeignKey('Stow', on_delete=models.CASCADE)
    status = models.ForeignKey(
        'Status', on_delete=models.CASCADE) 

views.py

def displaydata(request):
    results1 = Subtask.objects.prefetch_related(
        'moveTo', 'operationID', 'stow', 'status').all()

    return render(request, 'ee.html', {'Subtask': results1})

website

Insıde your Operation model add a int* function:

class Operation(models.Model):
    ...
    ...
    ...

    def __int__(self):
        return self.operationID 

*: int not str

Back to Top