From 7f7c6484eaa7714de798af6fbb06247e2b02468e Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 19 Dec 2023 23:42:46 -0500 Subject: [PATCH] membershipworks: Add Transaction model and admin Retroactively adding to the initial migration as this table already existed, just wasn't represented in the Django app yet --- membershipworks/admin.py | 9 ++- membershipworks/migrations/0001_initial.py | 76 ++++++++++++++++++++++ membershipworks/models.py | 37 +++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) diff --git a/membershipworks/admin.py b/membershipworks/admin.py index a983c27..2435475 100644 --- a/membershipworks/admin.py +++ b/membershipworks/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Member, Flag +from .models import Member, Flag, Transaction class ReadOnlyAdmin(admin.ModelAdmin): @@ -31,3 +31,10 @@ class FlagAdmin(ReadOnlyAdmin): list_filter = ["type"] show_facets = admin.ShowFacets.ALWAYS search_fields = ["name"] + + +@admin.register(Transaction) +class TransactionAdmin(ReadOnlyAdmin): + list_display = ["timestamp", "member", "name", "type", "sum", "note"] + list_filter = ["type"] + show_facets = admin.ShowFacets.ALWAYS diff --git a/membershipworks/migrations/0001_initial.py b/membershipworks/migrations/0001_initial.py index 77dbe53..591d838 100644 --- a/membershipworks/migrations/0001_initial.py +++ b/membershipworks/migrations/0001_initial.py @@ -280,4 +280,80 @@ class Migration(migrations.Migration): "managed": False, }, ), + migrations.CreateModel( + name="Transaction", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("sid", models.CharField(blank=True, max_length=27, null=True)), + ("timestamp", models.DateTimeField()), + ("type", models.TextField(blank=True, null=True)), + ( + "sum", + models.DecimalField( + blank=True, decimal_places=4, max_digits=13, null=True + ), + ), + ( + "fee", + models.DecimalField( + blank=True, decimal_places=4, max_digits=13, null=True + ), + ), + ("event_id", models.TextField(blank=True, null=True)), + ("for_what", models.TextField(blank=True, db_column="For", null=True)), + ("items", models.TextField(blank=True, db_column="Items", null=True)), + ( + "discount_code", + models.TextField(blank=True, db_column="Discount Code", null=True), + ), + ("note", models.TextField(blank=True, db_column="Note", null=True)), + ("name", models.TextField(blank=True, db_column="Name", null=True)), + ( + "contact_person", + models.TextField(blank=True, db_column="Contact Person", null=True), + ), + ( + "full_address", + models.TextField(blank=True, db_column="Full Address", null=True), + ), + ("street", models.TextField(blank=True, db_column="Street", null=True)), + ("city", models.TextField(blank=True, db_column="City", null=True)), + ( + "state_province", + models.TextField(blank=True, db_column="State/Province", null=True), + ), + ( + "postal_code", + models.TextField(blank=True, db_column="Postal Code", null=True), + ), + ( + "country", + models.TextField(blank=True, db_column="Country", null=True), + ), + ("phone", models.TextField(blank=True, db_column="Phone", null=True)), + ("email", models.TextField(blank=True, db_column="Email", null=True)), + ( + "member", + models.ForeignKey( + blank=True, + db_column="uid", + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="transactions", + to="membershipworks.member", + ), + ), + ], + options={ + "db_table": "transactions", + }, + ), ] diff --git a/membershipworks/models.py b/membershipworks/models.py index 43a2885..95ecd18 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -208,3 +208,40 @@ class MemberFlag(models.Model): fields=["member", "flag_id"], name="unique_member_flag" ) ] + + +class Transaction(models.Model): + sid = models.CharField(max_length=27, null=True, blank=True) + member = models.ForeignKey( + Member, + on_delete=models.PROTECT, + db_column="uid", + related_name="transactions", + null=True, + blank=True, + ) + timestamp = models.DateTimeField() + type = models.TextField(null=True, blank=True) + sum = models.DecimalField(max_digits=13, decimal_places=4, null=True, blank=True) + fee = models.DecimalField(max_digits=13, decimal_places=4, null=True, blank=True) + event_id = models.TextField(null=True, blank=True) + for_what = models.TextField(db_column="For", null=True, blank=True) + items = models.TextField(db_column="Items", null=True, blank=True) + discount_code = models.TextField(db_column="Discount Code", null=True, blank=True) + note = models.TextField(db_column="Note", null=True, blank=True) + name = models.TextField(db_column="Name", null=True, blank=True) + contact_person = models.TextField(db_column="Contact Person", null=True, blank=True) + full_address = models.TextField(db_column="Full Address", null=True, blank=True) + street = models.TextField(db_column="Street", null=True, blank=True) + city = models.TextField(db_column="City", null=True, blank=True) + state_province = models.TextField(db_column="State/Province", null=True, blank=True) + postal_code = models.TextField(db_column="Postal Code", null=True, blank=True) + country = models.TextField(db_column="Country", null=True, blank=True) + phone = models.TextField(db_column="Phone", null=True, blank=True) + email = models.TextField(db_column="Email", null=True, blank=True) + + def __str__(self): + return f"{self.type} [{self.member if self.member else self.name}] {self.timestamp}" + + class Meta: + db_table = "transactions"