1
Hello, everyone, I have a Django project that issues daily reports of a company’s activities. The project is a bit complex, but I’m going to give you a simple example of a relationship that’s similar to the problem I have.
from django.db import models
class Funcionario(models.Model):
nome = models.CharField('Nome', max_length=100)
# Fields...
def __str__(self):
return self.nome
class RelatorioDiario(models.Model):
# Fields...
funcionarios = models.ManyToManyField(Funcionario, verbose_name='Funcionários')
data = models.DateField('Data do Relatório')
def __str__(self):
return f'Relatório - {self.data}'
I have an employee called "Maria da Silva", which should be in the reports.
On day 1, I issued a report - one of the listed employees was "Maria da Silva". On the 2nd, same. ... On the 9th, "Maria da Silva" married and began to adopt her married name "Maria da Silva Santos".
No day 10, It is updated the employee registration. The next reports should come with the new name. So far, okay. The problem is that the way the relationship model is, this name change will impact the previous reports.
What I want is that, when updating the employee’s registration, the previous reports continue with the employee’s old name, namely, "Maria da Silva".
How to implement this?
Ever thought of treating the name as if it were a phone? in case, you would use another table and associate to this class as a foreign key.
– Carlos Cortez