web_AI-5/django/didgeridoo/currencies/models.py

32 lines
847 B
Python

from django.db import models
from decimal import Decimal
import datetime
class ExchangeRate_name(models.Model):
name = models.CharField(max_length=200, unique=True)
def __str__(self):
return self.name
class ExchangeRate_date(models.Model):
date = models.DateField('%Y-%m-%d', unique_for_date=True)
def __str__(self):
return str(self.date)
class ExchangeRate(models.Model):
name = models.ForeignKey(ExchangeRate_name)
date = models.ForeignKey(ExchangeRate_date)
exchange_rate_to_chf = models.DecimalField(max_digits=12,
decimal_places=5)
def __str__(self):
return str(self.name)
class Meta:
# https://simpleisbetterthancomplex.com/tips/2016/10/06/django-tip-17-earliest-and-latest.html
get_latest_by = 'name__name'