diff options
Diffstat (limited to 'alphabetlearning/payments')
-rw-r--r-- | alphabetlearning/payments/admin.py | 13 | ||||
-rw-r--r-- | alphabetlearning/payments/migrations/0008_remove_price_product_price_resource.py | 25 | ||||
-rw-r--r-- | alphabetlearning/payments/models.py | 5 | ||||
-rw-r--r-- | alphabetlearning/payments/views.py | 6 |
4 files changed, 39 insertions, 10 deletions
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 |