aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-10-19 19:43:59 +0100
committerMatthew Lemon <y@yulqen.org>2024-10-19 19:43:59 +0100
commit1e1a2f6ac2cadfbc57cc855a67498af097391caf (patch)
tree8e28486d182d6b4746d4feb22347badf21f5465d
parentae9bc97c743ea4d31a3f392db72a948d87d3b2ab (diff)
Changes the Resource to include Stripe reference
-rw-r--r--.ctags4
-rw-r--r--alphabetlearning/payments/admin.py13
-rw-r--r--alphabetlearning/payments/migrations/0008_remove_price_product_price_resource.py25
-rw-r--r--alphabetlearning/payments/models.py5
-rw-r--r--alphabetlearning/payments/views.py6
-rw-r--r--alphabetlearning/resources/migrations/0020_remove_resource_price_resource_stripe_product_id.py23
-rw-r--r--alphabetlearning/resources/models.py15
-rw-r--r--alphabetlearning/templates/payments/landingpage.html6
8 files changed, 77 insertions, 20 deletions
diff --git a/.ctags b/.ctags
new file mode 100644
index 0000000..25b92c3
--- /dev/null
+++ b/.ctags
@@ -0,0 +1,4 @@
+# Basic options
+--recurse=yes
+--tag-relative=yes
+--exclude=.git
diff --git a/alphabetlearning/payments/admin.py b/alphabetlearning/payments/admin.py
index f6a00a2..9588f3b 100644
--- a/alphabetlearning/payments/admin.py
+++ b/alphabetlearning/payments/admin.py
@@ -6,14 +6,14 @@ from .models import Product
from .models import ShoppingCart
from .models import Subscription
from .models import SubscriptionPlan
+from alphabetlearning.resources.models import Resource
-class PriceInlineAdmin(admin.TabularInline):
- model = Price
- extra = 0
+#class PriceAdmin(admin.ModelAdmin):
+# list_display =
-class ProductAdmin(admin.ModelAdmin):
- inlines = [PriceInlineAdmin]
+#class ProductAdmin(admin.ModelAdmin):
+# inlines = [PriceInlineAdmin]
class SubscriptionPlanAdmin(admin.ModelAdmin):
list_display = ('name', 'price', 'description', 'allowed_downloads')
@@ -31,7 +31,8 @@ class SubscriptionAdmin(admin.ModelAdmin):
list_display = ('user', 'is_active', 'start_date', 'end_date')
-admin.site.register(Product, ProductAdmin)
+#admin.site.register(Product, ProductAdmin)
+admin.site.register(Price)
admin.site.register(SubscriptionPlan)
admin.site.register(ShoppingCart)
admin.site.register(CartItem)
diff --git a/alphabetlearning/payments/migrations/0008_remove_price_product_price_resource.py b/alphabetlearning/payments/migrations/0008_remove_price_product_price_resource.py
new file mode 100644
index 0000000..9d52284
--- /dev/null
+++ b/alphabetlearning/payments/migrations/0008_remove_price_product_price_resource.py
@@ -0,0 +1,25 @@
+# Generated by Django 5.0.4 on 2024-10-19 15:11
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('payments', '0007_remove_cartitem_quantity_and_more'),
+ ('resources', '0020_remove_resource_price_resource_stripe_product_id'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='price',
+ name='product',
+ ),
+ migrations.AddField(
+ model_name='price',
+ name='resource',
+ field=models.ForeignKey(default=66, on_delete=django.db.models.deletion.CASCADE, related_name='price', to='resources.resource'),
+ preserve_default=False,
+ ),
+ ]
diff --git a/alphabetlearning/payments/models.py b/alphabetlearning/payments/models.py
index 62bcbde..0ad07fb 100644
--- a/alphabetlearning/payments/models.py
+++ b/alphabetlearning/payments/models.py
@@ -14,13 +14,16 @@ class Product(models.Model):
class Price(models.Model):
- product = models.ForeignKey(Product, on_delete=models.CASCADE)
+ resource = models.ForeignKey(Resource, on_delete=models.CASCADE, related_name="price")
price = models.IntegerField(default=0)
stripe_price_id = models.CharField(max_length=100)
def get_display_price(self):
return "{0:.2f}".format(self.price / 100)
+ def __str__(self):
+ return f"{self.price} for {self.resource.name}"
+
class ShoppingCart(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py
index 73a14c2..6bcb5a5 100644
--- a/alphabetlearning/payments/views.py
+++ b/alphabetlearning/payments/views.py
@@ -69,10 +69,10 @@ class ProductLandingPageView(TemplateView):
template_name = "payments/landingpage.html"
def get_context_data(self, **kwargs):
- product = Product.objects.get(name="Worksheet 1")
- prices = Price.objects.filter(product=product)
+ resource = Resource.objects.get(id=91)
+ prices = Price.objects.filter(resource=resource)
context = super(ProductLandingPageView, self).get_context_data(**kwargs)
- context.update({"product": product, "prices": prices})
+ context.update({"resource": resource, "prices": prices})
return context
diff --git a/alphabetlearning/resources/migrations/0020_remove_resource_price_resource_stripe_product_id.py b/alphabetlearning/resources/migrations/0020_remove_resource_price_resource_stripe_product_id.py
new file mode 100644
index 0000000..088556b
--- /dev/null
+++ b/alphabetlearning/resources/migrations/0020_remove_resource_price_resource_stripe_product_id.py
@@ -0,0 +1,23 @@
+# Generated by Django 5.0.4 on 2024-10-19 15:11
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('resources', '0019_alter_pdfpagesnapshot_options_and_more'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='resource',
+ name='price',
+ ),
+ migrations.AddField(
+ model_name='resource',
+ name='stripe_product_id',
+ field=models.CharField(default='baws', max_length=100),
+ preserve_default=False,
+ ),
+ ]
diff --git a/alphabetlearning/resources/models.py b/alphabetlearning/resources/models.py
index 3dfad06..ebdf98d 100644
--- a/alphabetlearning/resources/models.py
+++ b/alphabetlearning/resources/models.py
@@ -37,13 +37,14 @@ DESC_HELP_TEXT = """
# Create your models here.
class Resource(models.Model):
name = models.CharField(max_length=255, null=False)
- price = models.DecimalField(
- max_digits=6,
- decimal_places=2,
- default=0.00,
- null=False,
- blank=False,
- )
+ stripe_product_id = models.CharField(max_length=100)
+ #price = models.DecimalField(
+ # max_digits=6,
+ # decimal_places=2,
+ # default=0.00,
+ # null=False,
+ # blank=False,
+ #)
thumbnail_filenames = models.JSONField(
null=False,
verbose_name="Thumbnail filenames",
diff --git a/alphabetlearning/templates/payments/landingpage.html b/alphabetlearning/templates/payments/landingpage.html
index 9897301..5c3b2cc 100644
--- a/alphabetlearning/templates/payments/landingpage.html
+++ b/alphabetlearning/templates/payments/landingpage.html
@@ -2,12 +2,12 @@
{% block content %}
<div class="container my-5">
<div class="row">
- <h2>Welcome to PyBlackbird - Buy this</h2>
+ <h2>Mock Shopping Card</h2>
<section>
<div class="product">
<div class="description">
- <h3>{{ product.name }}</h3>
+ <h3>{{ resource.name }}</h3>
<hr/>
{% for price in prices %}
@@ -26,4 +26,4 @@
</div>
-{% endblock content %} \ No newline at end of file
+{% endblock content %}