justdjango / dj-video-membership Goto Github PK
View Code? Open in Web Editor NEWDjango Video Membership website
License: MIT License
Django Video Membership website
License: MIT License
Hi Matthew,
When trying to recreate the project on my own I had to go through python shell to manually create the pricing tiers. To avoid errors and waste of time I thougt it would be more efficient to add the pricing creation in the "makesuper" cmd. Here is the small correction I wrote.
class Command(BaseCommand):
def handle(self, *args, **options):
if not User.objects.filter(username="admin").exists():
if settings.DEBUG:
password = 'admin'
else:
password = randomStringwithDigitsAndSymbols()
user = User.objects.create_superuser(
"admin", "[email protected]", password)
if not Pricing.objects.filter(name='Free account').exists():
free_account = Pricing.objects.create(
name="Free account",
slug="free-account",
stripe_price_id="price_123456",
price=0.00,
currency="eu"
)
free_account.save()
free_trial_pricing = Pricing.objects.get(name='Free_account')
subscription = Subscription.objects.create(
user=user,
pricing=free_trial_pricing
)
stripe_customer = stripe.Customer.create(
email=user.email
)
stripe_subscription = stripe.Subscription.create(
customer=stripe_customer["id"],
items=[{'price': 'price_123456'}], # my project needs people to have unlimited free account (no trialing)
)
subscription.status = stripe_subscription["status"]
subscription.stripe_subscription_id = stripe_subscription["id"]
subscription.save()
user.stripe_customer_id = stripe_customer["id"]
user.save()
else:
user = User.objects.get(username="admin")[...]
Feel free to use it. Thank you for your courses,
Gianni Vullo
Edit: I added and if statement before the pricing creation method to prevent databases bad interactions in case of running twice the commmand.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.