From ee12a15b5e7e1016ea4894f13b4e06e9e53f2ddd Mon Sep 17 00:00:00 2001 From: jhyns Date: Thu, 25 May 2023 14:50:20 +0900 Subject: [PATCH] Add models for graph app --- graph/models.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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}"