Django 'join' tabels
I have 3 Tabels in Django
class Transactions(models.Model):
public_key = models.ForeignKey(Keys, on_delete=models.CASCADE)
txid = models.CharField(max_length=30)
timestamp = models.DateTimeField()
hash = models.CharField(max_length=64)
block = models.IntegerField()
amount = models.IntegerField()
saldo = models.IntegerField()
fee = models.IntegerField()
fiat_CHF = models.FloatField(default=0)
fiat_USD = models.FloatField(default=0)
fiat_EUR = models.FloatField(default=0)
position = models.IntegerField(default=0)
class Price(models.Model):
date = models.DateTimeField()
price = models.FloatField()
fiat = models.ForeignKey(Currencies, on_delete=models.DO_NOTHING)
class PriceTextBackup(models.Model):
date = models.CharField(max_length=20)
price = models.FloatField()
fiat = models.ForeignKey(Currencies, on_delete=models.DO_NOTHING)
This is from a Bitcoin App, the Transaction Table contains the exact time when transaction was mined. Now I want to load the stored bitcoin price for that day
for example the transaction may have a timestamp of 2000-01-01 12:10:10
and the price 2000-01-01
so i want to join or link them. It doesn't have to be in database.
I did something similar in a diffrent page to calculate the average price, i load both tables and 'join' them.
In the end I want to display the transaction with a price. this price can come from price, pricetextbackup or be 0.
Can this be achived and how?