diff --git a/graph/models.py b/graph/models.py index 71a8362..02719e8 100644 --- a/graph/models.py +++ b/graph/models.py @@ -1,3 +1,32 @@ from django.db import models -# Create your models here. +from market.models import Product + + +class Transaction(models.Model): + product = models.ForeignKey( + Product, on_delete=models.CASCADE, related_name="transactions" + ) + price = models.IntegerField() + created_at = models.DateTimeField(auto_now_add=True) + + class Meta: + ordering = ["-created_at"] + + def __str__(self): + return f"{self.product} : {self.price}" + + +class MonthlyTransaction(models.Model): + product = models.ForeignKey( + Product, on_delete=models.CASCADE, related_name="monthly_transactions" + ) + year = models.IntegerField() + month = models.IntegerField() + price = models.IntegerField() + + class Meta: + ordering = ["-year", "-month"] + + def __str__(self): + return f"{self.product} : {self.year}-{self.month}"