我有三个有历史记录的模型:
class WifiUser(models.Model):
....
wifiDevice = models.OneToOneField(WifiDevice, on_delete=models.CASCADE, default=None)
wifiSim = models.OneToOneField(WifiSim, on_delete=models.CASCADE, default=None)
history = HistoricalRecords()
class WifiDevice(models.Model):
....
history = HistoricalRecords()
class WifiSim(models.Model):
....
history = HistoricalRecords()我想用对应的外键历史记录来跟踪历史。但是当访问Wifiuser的历史时,我得到了WifiDevice和WifiSim的最新值。我希望WifiDevice和WifiSim的历史记录指向他们的记录。对此最好的方法是什么?
发布于 2020-06-20 06:14:23
为了跟踪历史,而不是只显示最后一个对象,我建议您为历史添加一个模型,其中包含wifiUser wifiDevice和wifiSim,也许还可以添加访问日期和时间的日期,以便自动添加日期我建议您查看此答案(Django auto now and auto add now)
发布于 2020-08-09 06:37:17
我在Upwork上看到你的帖子,你需要覆盖两个模型WifiDevice和WifiSim的字符串方法,如下所示:
class WifiDevice(models.Model):
....
history = HistoricalRecords()
def __str__ (self):
return self.history // the solution
class WifiSim(models.Model):
....
history = HistoricalRecords()
def __str__ (self):
return self.history // the solution 发布于 2020-06-24 21:29:43
class BilingualCorpus(models.Model):
file_url = models.FileField(upload_to='corpus_files/', validators=[FileExtensionValidator(allowed_extensions=['txt', 'csv', 'tmx', 'xlsx'])])
file_name = models.CharField(max_length=255, default='none')
name = models.CharField(max_length=50,default='none')
s_lang = models.CharField(max_length=5,default='en')
t_lang = models.CharField(max_length=5,default='th')
note = models.TextField(blank=True)
user = models.ForeignKey(User, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True, blank=True)
updated_at = models.DateTimeField(auto_now=True, blank=True)
class CorpusStatus(models.Model):
status = models.CharField(max_length=50, default='Unchecked')
class BilingualSentence(models.Model):
corpus = models.ForeignKey(BilingualCorpus, on_delete=models.CASCADE)
source = models.TextField(blank=True)
target = models.TextField(blank=True)
status = models.ForeignKey(CorpusStatus, blank=True, null=True, on_delete=models.SET_NULL)https://stackoverflow.com/questions/62478916
复制相似问题