From 5efb054c306af5ce629c6ebfb175c0ce546ab0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sat, 18 Feb 2023 20:57:03 +0100 Subject: [PATCH] Add support for purchase ownership information Closes #48 --- CHANGELOG.md | 1 + games/forms.py | 1 + .../0013_purchase_ownership_type.py | 31 +++++++++++++++++++ games/models.py | 22 +++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 games/migrations/0013_purchase_ownership_type.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 787bd60..2f9e104 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Unreleased +* Add support for purchase ownership information (https://git.kucharczyk.xyz/lukas/timetracker/issues/48) * Add support for purchase prices * Add support for game editions (https://git.kucharczyk.xyz/lukas/timetracker/issues/28) diff --git a/games/forms.py b/games/forms.py index 3c28af0..08662ea 100644 --- a/games/forms.py +++ b/games/forms.py @@ -32,6 +32,7 @@ class PurchaseForm(forms.ModelForm): "date_refunded", "price", "price_currency", + "ownership_type", ] diff --git a/games/migrations/0013_purchase_ownership_type.py b/games/migrations/0013_purchase_ownership_type.py new file mode 100644 index 0000000..02a3a23 --- /dev/null +++ b/games/migrations/0013_purchase_ownership_type.py @@ -0,0 +1,31 @@ +# Generated by Django 4.1.5 on 2023-02-18 19:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("games", "0012_purchase_price_purchase_price_currency"), + ] + + operations = [ + migrations.AddField( + model_name="purchase", + name="ownership_type", + field=models.CharField( + choices=[ + ("ph", "Physical"), + ("di", "Digital"), + ("du", "Digital Upgrade"), + ("re", "Rented"), + ("bo", "Borrowed"), + ("tr", "Trial"), + ("de", "Demo"), + ("pi", "Pirated"), + ], + default="di", + max_length=2, + ), + ), + ] diff --git a/games/models.py b/games/models.py index b9d8e44..6070c4a 100644 --- a/games/models.py +++ b/games/models.py @@ -26,12 +26,34 @@ class Edition(models.Model): class Purchase(models.Model): + PHYSICAL = "ph" + DIGITAL = "di" + DIGITALUPGRADE = "du" + RENTED = "re" + BORROWED = "bo" + TRIAL = "tr" + DEMO = "de" + PIRATED = "pi" + OWNERSHIP_TYPES = [ + (PHYSICAL, "Physical"), + (DIGITAL, "Digital"), + (DIGITALUPGRADE, "Digital Upgrade"), + (RENTED, "Rented"), + (BORROWED, "Borrowed"), + (TRIAL, "Trial"), + (DEMO, "Demo"), + (PIRATED, "Pirated"), + ] + edition = models.ForeignKey("Edition", on_delete=models.CASCADE) platform = models.ForeignKey("Platform", on_delete=models.CASCADE) date_purchased = models.DateField() date_refunded = models.DateField(blank=True, null=True) price = models.IntegerField(default=0) price_currency = models.CharField(max_length=3, default="USD") + ownership_type = models.CharField( + max_length=2, choices=OWNERSHIP_TYPES, default=DIGITAL + ) def __str__(self): return f"{self.edition} ({self.platform})"