Setting image back to default image
I have a quick question pertaining to setting image back to default image. I have a user profile model:
from django.contrib.auth import get_user_model
User = get_user_model()
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="user_images/default.png",
upload_to="user_images", null=True, blank=True)
email = models.EmailField(null=True, blank=True)
following = models.ManyToManyField(User, blank=True, related_name='children')
My question is why doesn't the default image get applied to the image field when an user updates the profile after deleting his or her profile image? I fixed the issue by overriding the save() method, but I would like to understand why. Can someone explain it? Thank you very much.
def save(self, *args, **kwargs):
if not self.image:
self.image = 'user_images/default.png'
super(Profile, self).save(*args, **kwargs)
/r/djangolearning
https://redd.it/1cvs2li
I have a quick question pertaining to setting image back to default image. I have a user profile model:
from django.contrib.auth import get_user_model
User = get_user_model()
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="user_images/default.png",
upload_to="user_images", null=True, blank=True)
email = models.EmailField(null=True, blank=True)
following = models.ManyToManyField(User, blank=True, related_name='children')
My question is why doesn't the default image get applied to the image field when an user updates the profile after deleting his or her profile image? I fixed the issue by overriding the save() method, but I would like to understand why. Can someone explain it? Thank you very much.
def save(self, *args, **kwargs):
if not self.image:
self.image = 'user_images/default.png'
super(Profile, self).save(*args, **kwargs)
/r/djangolearning
https://redd.it/1cvs2li
Reddit
From the djangolearning community on Reddit
Explore this post and more from the djangolearning community
Flask for SaaS product and microservice arhitecture
I am currently given task to work on system design for MVP application for SaaS solution selling microproducts.
Users will pay for lets say notifications, specific data, and different type of things in application.
My idea is: Next.js for frontend, Auth0, API gateway and flask microservices.
From your expirience, what is the benefit of flask compared to Django or FastAPI for this kind of project that will potentially have thousands of active users?
Should API gateway be responsible for authorization based on what microservices user bought or better to keep it in code/microservices?
Any insight/doucmentation and experience is greatley appreciated :)
/r/flask
https://redd.it/1cvcupl
I am currently given task to work on system design for MVP application for SaaS solution selling microproducts.
Users will pay for lets say notifications, specific data, and different type of things in application.
My idea is: Next.js for frontend, Auth0, API gateway and flask microservices.
From your expirience, what is the benefit of flask compared to Django or FastAPI for this kind of project that will potentially have thousands of active users?
Should API gateway be responsible for authorization based on what microservices user bought or better to keep it in code/microservices?
Any insight/doucmentation and experience is greatley appreciated :)
/r/flask
https://redd.it/1cvcupl
Reddit
From the flask community on Reddit
Explore this post and more from the flask community
Django prerequisite other than python
I know understanding basic python code is enough to start, but what do I need to know to actually know how django works ? I have only built basic php/html web before.
/r/django
https://redd.it/1cvvrvb
I know understanding basic python code is enough to start, but what do I need to know to actually know how django works ? I have only built basic php/html web before.
/r/django
https://redd.it/1cvvrvb
Reddit
From the django community on Reddit
Explore this post and more from the django community
Monday Daily Thread: Project ideas!
# Weekly Thread: Project Ideas 💡
Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.
## How it Works:
1. **Suggest a Project**: Comment your project idea—be it beginner-friendly or advanced.
2. **Build & Share**: If you complete a project, reply to the original comment, share your experience, and attach your source code.
3. **Explore**: Looking for ideas? Check out Al Sweigart's ["The Big Book of Small Python Projects"](https://www.amazon.com/Big-Book-Small-Python-Programming/dp/1718501242) for inspiration.
## Guidelines:
* Clearly state the difficulty level.
* Provide a brief description and, if possible, outline the tech stack.
* Feel free to link to tutorials or resources that might help.
# Example Submissions:
## Project Idea: Chatbot
**Difficulty**: Intermediate
**Tech Stack**: Python, NLP, Flask/FastAPI/Litestar
**Description**: Create a chatbot that can answer FAQs for a website.
**Resources**: [Building a Chatbot with Python](https://www.youtube.com/watch?v=a37BL0stIuM)
# Project Idea: Weather Dashboard
**Difficulty**: Beginner
**Tech Stack**: HTML, CSS, JavaScript, API
**Description**: Build a dashboard that displays real-time weather information using a weather API.
**Resources**: [Weather API Tutorial](https://www.youtube.com/watch?v=9P5MY_2i7K8)
## Project Idea: File Organizer
**Difficulty**: Beginner
**Tech Stack**: Python, File I/O
**Description**: Create a script that organizes files in a directory into sub-folders based on file type.
**Resources**: [Automate the Boring Stuff: Organizing Files](https://automatetheboringstuff.com/2e/chapter9/)
Let's help each other grow. Happy
/r/Python
https://redd.it/1cw25ip
# Weekly Thread: Project Ideas 💡
Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.
## How it Works:
1. **Suggest a Project**: Comment your project idea—be it beginner-friendly or advanced.
2. **Build & Share**: If you complete a project, reply to the original comment, share your experience, and attach your source code.
3. **Explore**: Looking for ideas? Check out Al Sweigart's ["The Big Book of Small Python Projects"](https://www.amazon.com/Big-Book-Small-Python-Programming/dp/1718501242) for inspiration.
## Guidelines:
* Clearly state the difficulty level.
* Provide a brief description and, if possible, outline the tech stack.
* Feel free to link to tutorials or resources that might help.
# Example Submissions:
## Project Idea: Chatbot
**Difficulty**: Intermediate
**Tech Stack**: Python, NLP, Flask/FastAPI/Litestar
**Description**: Create a chatbot that can answer FAQs for a website.
**Resources**: [Building a Chatbot with Python](https://www.youtube.com/watch?v=a37BL0stIuM)
# Project Idea: Weather Dashboard
**Difficulty**: Beginner
**Tech Stack**: HTML, CSS, JavaScript, API
**Description**: Build a dashboard that displays real-time weather information using a weather API.
**Resources**: [Weather API Tutorial](https://www.youtube.com/watch?v=9P5MY_2i7K8)
## Project Idea: File Organizer
**Difficulty**: Beginner
**Tech Stack**: Python, File I/O
**Description**: Create a script that organizes files in a directory into sub-folders based on file type.
**Resources**: [Automate the Boring Stuff: Organizing Files](https://automatetheboringstuff.com/2e/chapter9/)
Let's help each other grow. Happy
/r/Python
https://redd.it/1cw25ip
The possibility to build Android apps with python professionally is here and needs your support.
You guys really need to check this. I believe new comers to python would love to tinker with the android ecosystem from the safety of python :-)
Imgur: https://imgur.com/gallery/DtfwOVi
https://www.kickstarter.com/projects/kivyschool/the-pain-free-python-on-android-essentials-course
Edit: added imgur link.
/r/Python
https://redd.it/1cvvy36
You guys really need to check this. I believe new comers to python would love to tinker with the android ecosystem from the safety of python :-)
Imgur: https://imgur.com/gallery/DtfwOVi
https://www.kickstarter.com/projects/kivyschool/the-pain-free-python-on-android-essentials-course
Edit: added imgur link.
/r/Python
https://redd.it/1cvvy36
Imgur
Kivy app - Album on Imgur
Discover the magic of the internet at Imgur, a community powered entertainment destination. Lift your spirits with funny jokes, trending memes, entertaining gifs, inspiring stories, viral videos, and so much more from users like mhndphantom91911.
Best way to store Discount Code used in a purchase when codes are allow to change over time
Let's say you have the following models:
class Product(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
price = models.DecimalField(max_digits=6, decimal_places=2)
class Purchase(models.Model):
customer = models.ForeignKey(User, on_delete=models.CASCADE)
total = models.DecimalField(max_digits=8, decimal_places=2)
class PurchaseItem(models.Model):
purchase = models.ForeignKey(Purchase, related_name='items', on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
price = models.DecimalField(max_digits=6, decimal_places=2)
class Discount(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
code = models.CharField(max_length=50, unique=True)
discount_percent = models.IntegerField()
If I want to store which discount code was used for a purchase I can do something like this:
class PurchaseItem(models.Model):
/r/django
https://redd.it/1cw9iw7
Let's say you have the following models:
class Product(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
price = models.DecimalField(max_digits=6, decimal_places=2)
class Purchase(models.Model):
customer = models.ForeignKey(User, on_delete=models.CASCADE)
total = models.DecimalField(max_digits=8, decimal_places=2)
class PurchaseItem(models.Model):
purchase = models.ForeignKey(Purchase, related_name='items', on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
price = models.DecimalField(max_digits=6, decimal_places=2)
class Discount(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
code = models.CharField(max_length=50, unique=True)
discount_percent = models.IntegerField()
If I want to store which discount code was used for a purchase I can do something like this:
class PurchaseItem(models.Model):
/r/django
https://redd.it/1cw9iw7
Reddit
From the django community on Reddit
Explore this post and more from the django community
ML Flask app deployed to AWS
So, for the past weekend I’ve been attempting to launch a small one endpoint Flask App that has a couple libraries like open cv, pandas, scikit and a specific library called Qreader that are all a little bit heavy, which made me move away from using something like AWS Chalice that was a quick deploy to lambdas.
I am fairly new to all cloud technologies, I’ve deployed some stuff here or there on AWS and azure but nothing has given me the trouble this has lol.
Any tutorial or advice? Mostly where I fall apart comes when I have gunicorn up but then when I try to setup logs or have it run in the background something like that it all blows up and can’t get it back up running. How do you even automate this to a pipeline CI/CD setup if it takes so many commands and setup to just get it up the first time. Again, I’m newish to this so if I’m saying something dumb call me out on it I’m trying to learn! Not sure if that makes a lot of sense? Any help is appreciated.
/r/flask
https://redd.it/1cw7l19
So, for the past weekend I’ve been attempting to launch a small one endpoint Flask App that has a couple libraries like open cv, pandas, scikit and a specific library called Qreader that are all a little bit heavy, which made me move away from using something like AWS Chalice that was a quick deploy to lambdas.
I am fairly new to all cloud technologies, I’ve deployed some stuff here or there on AWS and azure but nothing has given me the trouble this has lol.
Any tutorial or advice? Mostly where I fall apart comes when I have gunicorn up but then when I try to setup logs or have it run in the background something like that it all blows up and can’t get it back up running. How do you even automate this to a pipeline CI/CD setup if it takes so many commands and setup to just get it up the first time. Again, I’m newish to this so if I’m saying something dumb call me out on it I’m trying to learn! Not sure if that makes a lot of sense? Any help is appreciated.
/r/flask
https://redd.it/1cw7l19
Reddit
From the flask community on Reddit
Explore this post and more from the flask community
Looking for suggestions on a good tutorial or material to understand django dataset queries
Hello,
I've been working on a project that has an 'estimate' template, view, model, form, and I would like the dropdown menu on the left side which has clients from a model called ClientRecords as well as the the dropdown menu on the right which has employees from a model called EmployeeRecords. I would like to be able to select a person from either menu and have the data like names and phone numbers populate. It would be really cool if it could do that with just the selection of the dropdown.
I'm looking for some guidance because I don't really know what the word is for what I am looking for. Maybe from the description and the picture someone can point me in the right direction.
Thank you!
current template look
/r/djangolearning
https://redd.it/1cw6dio
Hello,
I've been working on a project that has an 'estimate' template, view, model, form, and I would like the dropdown menu on the left side which has clients from a model called ClientRecords as well as the the dropdown menu on the right which has employees from a model called EmployeeRecords. I would like to be able to select a person from either menu and have the data like names and phone numbers populate. It would be really cool if it could do that with just the selection of the dropdown.
I'm looking for some guidance because I don't really know what the word is for what I am looking for. Maybe from the description and the picture someone can point me in the right direction.
Thank you!
current template look
/r/djangolearning
https://redd.it/1cw6dio
Allauth + DRF
Hello guys 👋
As we know allauth dropped headless support and wanna use that with drf + vue.js and I kinda stuck here during auth and secure api endpoints, so do you guys have any public project available with these technologies so that I can have a look at the code? Something like a boilerplate.
/r/django
https://redd.it/1cwdmkh
Hello guys 👋
As we know allauth dropped headless support and wanna use that with drf + vue.js and I kinda stuck here during auth and secure api endpoints, so do you guys have any public project available with these technologies so that I can have a look at the code? Something like a boilerplate.
/r/django
https://redd.it/1cwdmkh
Reddit
From the django community on Reddit
Explore this post and more from the django community
Best/fastest way to get going with SaaS subscription payments?
I'm working on a SaaS app and starting to work on subscriptions/payments.
My project is vanilla Django with htmx, and I'd prefer to use Stripe. I used Stripe a few years ago to build an ecom store and Stripe Connect to build a marketplace, but never a subscription service. I'm starting from zero here, so that means I need:
templates/forms
data models
payment processor
I'm not sure if I should just start hacking with the Stripe Python package or go with something more polished. Hoping to not create a load of tech debt by being dumb now.
Eventually I'd like to support trial subscriptions, upgrades/downgrades...and whatever else is normal in SaaS payments.
So I looked into a few things:
Stripe no-code subscriptions: Can start quickly, but have to add subscriptions by hand
[Stripe with embedded forms](https://docs.stripe.com/billing/subscriptions/build-subscriptions?platform=web&ui=embedded-form): Guessing this is the least work?
dj-stripe: Docs aren't great, but is somewhat funded by Stripe.
[drf-stripe-subscription](https://github.com/oscarychen/drf-stripe-subscription/tree/master): Don't plan to use DRF, but has useful code.
Paddle: Payment service, looks like it does lots of stuff, maybe easier than integrating Stripe? Costs 5% + $.30
[Chargebee](https://www.chargebee.com/): Payment service, set up for subscriptions. Free up to $250k rev, then $599/mo (plus processor fees?)
A SaaS Subscription Data Model:
/r/django
https://redd.it/1cwndtd
I'm working on a SaaS app and starting to work on subscriptions/payments.
My project is vanilla Django with htmx, and I'd prefer to use Stripe. I used Stripe a few years ago to build an ecom store and Stripe Connect to build a marketplace, but never a subscription service. I'm starting from zero here, so that means I need:
templates/forms
data models
payment processor
I'm not sure if I should just start hacking with the Stripe Python package or go with something more polished. Hoping to not create a load of tech debt by being dumb now.
Eventually I'd like to support trial subscriptions, upgrades/downgrades...and whatever else is normal in SaaS payments.
So I looked into a few things:
Stripe no-code subscriptions: Can start quickly, but have to add subscriptions by hand
[Stripe with embedded forms](https://docs.stripe.com/billing/subscriptions/build-subscriptions?platform=web&ui=embedded-form): Guessing this is the least work?
dj-stripe: Docs aren't great, but is somewhat funded by Stripe.
[drf-stripe-subscription](https://github.com/oscarychen/drf-stripe-subscription/tree/master): Don't plan to use DRF, but has useful code.
Paddle: Payment service, looks like it does lots of stuff, maybe easier than integrating Stripe? Costs 5% + $.30
[Chargebee](https://www.chargebee.com/): Payment service, set up for subscriptions. Free up to $250k rev, then $599/mo (plus processor fees?)
A SaaS Subscription Data Model:
/r/django
https://redd.it/1cwndtd
Stripe
Create subscriptions
Set up recurring payments by offering subscriptions to your service.
Building a Digital Filter: How it works + Simulation + Example
https://youtu.be/Aq_SOvR1Sxs?si=FoHOxfi088ETApkJ
/r/IPython
https://redd.it/1cwhory
https://youtu.be/Aq_SOvR1Sxs?si=FoHOxfi088ETApkJ
/r/IPython
https://redd.it/1cwhory
YouTube
Building a Digital Filter: How it works + Simulation + Example
Everything important you need to know to start designing your own digital filters. Thank you very much C. Daniel Boschen.
Links:
- Daniel's Linked In: https://www.linkedin.com/in/danboschen/
- PCB Simulation vs. Real Board - DC Currents and Voltage drop…
Links:
- Daniel's Linked In: https://www.linkedin.com/in/danboschen/
- PCB Simulation vs. Real Board - DC Currents and Voltage drop…
Reactive programming for Python with live-cells-py
live-cells-py (Live Cells Python) is a reactive programming library which I ported from [Live Cells](https://livecells.viditrack.com/) for Dart.
# What my project Does:
You can declare *cells* which are observable containers for data:
import live_cells as lc
a = lc.mutable(0)
Cells can be defined as a function of other cells:
a = lc.mutable(0)
b = lc.mutable(1)
c = lc.computed(lambda: a() + b())
`c` is defined as the sum of the values of cells `a` and `b`. The value of `c` is automatically recomputed when the value of either `a` or `b` changes.
The definition of `c` can be simplified to the following:
c = a + b
Which reads like an ordinary variable definition
You can define a *watch* function which runs whenever the value of a cell changes:
lc.watch(lambda: print(f'The sum is {c()}'))
This watch function, which prints the value of `c` to standard output, is run automatically whenever the value of `c` changes.
More complex computed cells and watch functions can be defined using decorators:
n = lc.mutable(5)
@lc.computed
/r/Python
https://redd.it/1cwcm7f
live-cells-py (Live Cells Python) is a reactive programming library which I ported from [Live Cells](https://livecells.viditrack.com/) for Dart.
# What my project Does:
You can declare *cells* which are observable containers for data:
import live_cells as lc
a = lc.mutable(0)
Cells can be defined as a function of other cells:
a = lc.mutable(0)
b = lc.mutable(1)
c = lc.computed(lambda: a() + b())
`c` is defined as the sum of the values of cells `a` and `b`. The value of `c` is automatically recomputed when the value of either `a` or `b` changes.
The definition of `c` can be simplified to the following:
c = a + b
Which reads like an ordinary variable definition
You can define a *watch* function which runs whenever the value of a cell changes:
lc.watch(lambda: print(f'The sum is {c()}'))
This watch function, which prints the value of `c` to standard output, is run automatically whenever the value of `c` changes.
More complex computed cells and watch functions can be defined using decorators:
n = lc.mutable(5)
@lc.computed
/r/Python
https://redd.it/1cwcm7f
Viditrack
Live Cells | Live Cells
Live Cells Library Documentation
Dive into DevOps ebook Humble Bundle supporting the Python Software Foundation
https://www.humblebundle.com/books/dive-into-dev-ops-no-starch-books
Be sure to click on "Adjust Donation" and "Custom Amount" and then max out the amount going to the Python Software Foundation. (From $1.75 to $24.50!)
For $30 you get the following ebooks from No Starch Press:
978-1718501928 2021 Automate the Boring Stuff with Python, 2nd Edition
978-1593275891 2014 DevOps for the Desperate
978-1593278632 2018 How Linux Works, 3rd Edition
978-1593271411 2007 The Book of Kubernetes
978-1593274764 2013 PowerShell for Sysadmins
978-1593278922 2018 Practical Vulnerability Management
978-1593272036 2010 Practical SQL, 2nd Edition
978-1593275099 2013 Practical Linux Forensics
978-1718500884 2021 Eloquent JavaScript, 3rd Edition
978-1718503007 2023 Cybersecurity for Small Networks
978-1593279943 2020 The Linux Command Line, 2nd Edition
978-1593279523 2019 Web Security for Developers
978-1718501485
/r/Python
https://redd.it/1cwqkx7
https://www.humblebundle.com/books/dive-into-dev-ops-no-starch-books
Be sure to click on "Adjust Donation" and "Custom Amount" and then max out the amount going to the Python Software Foundation. (From $1.75 to $24.50!)
For $30 you get the following ebooks from No Starch Press:
978-1718501928 2021 Automate the Boring Stuff with Python, 2nd Edition
978-1593275891 2014 DevOps for the Desperate
978-1593278632 2018 How Linux Works, 3rd Edition
978-1593271411 2007 The Book of Kubernetes
978-1593274764 2013 PowerShell for Sysadmins
978-1593278922 2018 Practical Vulnerability Management
978-1593272036 2010 Practical SQL, 2nd Edition
978-1593275099 2013 Practical Linux Forensics
978-1718500884 2021 Eloquent JavaScript, 3rd Edition
978-1718503007 2023 Cybersecurity for Small Networks
978-1593279943 2020 The Linux Command Line, 2nd Edition
978-1593279523 2019 Web Security for Developers
978-1718501485
/r/Python
https://redd.it/1cwqkx7
Humble Bundle
Humble Tech Book Bundle: Networking, Sysadmin, and DevOps by No Starch
IT pros, this book bundle will get you up to speed with DevOps, teach you Linux tips and tricks, and demystify containerization. Your purchase helps charity!
Using an existing PostgresDB in a new Django project
I used inspectdb to auto generate models, and four fields were skipped without warning, there's something like 20 fields so it was hard to immediately detect, and fortunately during testing I did find that there were missing fields. My question is how have you gone about moving over an existing db into django -- consider for example if I have dozens of tables to move over and want some sort of guarantee or alerting when fields are omitted. Is there something more robust than inspectdb? Or, what is your process for reviewing a large set of generated models from inspectdb that minimizes human error? My approach thus far was to print out column names, print out db metadata, and cross compare -- is this the best?
/r/django
https://redd.it/1cwni82
I used inspectdb to auto generate models, and four fields were skipped without warning, there's something like 20 fields so it was hard to immediately detect, and fortunately during testing I did find that there were missing fields. My question is how have you gone about moving over an existing db into django -- consider for example if I have dozens of tables to move over and want some sort of guarantee or alerting when fields are omitted. Is there something more robust than inspectdb? Or, what is your process for reviewing a large set of generated models from inspectdb that minimizes human error? My approach thus far was to print out column names, print out db metadata, and cross compare -- is this the best?
/r/django
https://redd.it/1cwni82
Reddit
From the django community on Reddit
Explore this post and more from the django community
Tuesday Daily Thread: Advanced questions
# Weekly Wednesday Thread: Advanced Questions 🐍
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
## How it Works:
1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.
## Guidelines:
* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.
## Recommended Resources:
* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.
## Example Questions:
1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the
/r/Python
https://redd.it/1cwuc7k
# Weekly Wednesday Thread: Advanced Questions 🐍
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
## How it Works:
1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.
## Guidelines:
* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.
## Recommended Resources:
* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.
## Example Questions:
1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the
/r/Python
https://redd.it/1cwuc7k
Discord
Join the Python Discord Server!
We're a large community focused around the Python programming language. We believe that anyone can learn to code. | 412982 members
Dash Pip Components
Hey everyone, just released 8 new pip components for plotly and dash including:
`Full Calendar Component` - A Full Calendar Component for Dash
`Dash Emoji Mart` - A Slack-like Emoji Picker for Dash
`Dash Image Gallery` - A Image Gallery Component for Dash
`Dash Insta Stories` - An Instagram Stories Component for Dash
Documentation can be found here:
https://pip-install-python. com/
The repo for the github can be found here:
https://github.com/pip-install-python/pip-docs
/r/flask
https://redd.it/1cwp5x7
Hey everyone, just released 8 new pip components for plotly and dash including:
`Full Calendar Component` - A Full Calendar Component for Dash
Dash Summernote - A rich text WYSIWYG Editor for Dash`Dash Emoji Mart` - A Slack-like Emoji Picker for Dash
Dash Charty - A Charting Library for Dash`Dash Image Gallery` - A Image Gallery Component for Dash
Dash Swiper - A Swiper Component for Dash`Dash Insta Stories` - An Instagram Stories Component for Dash
Dash Credit Cards - A Credit Card Component for DashDocumentation can be found here:
https://pip-install-python. com/
The repo for the github can be found here:
https://github.com/pip-install-python/pip-docs
/r/flask
https://redd.it/1cwp5x7
try... except... finally!
Haven't seen this syntax used very often and was wondering why. During error handling, if you have something to run independent of the success, you can use finally.
# VS
# VS
/r/Python
https://redd.it/1cx0dh4
Haven't seen this syntax used very often and was wondering why. During error handling, if you have something to run independent of the success, you can use finally.
from your_library import DataProcess
engine = DataProcess()
try:
engine.io()
engine.process()
engine.some_more_io()
except Exception as e:
engine.revert()
raise e
finally:
engine.cleanup()
# VS
from your_library import DataProcess
engine = DataProcess()
try:
engine.io()
engine.process()
engine.some_more_io()
except Exception as e:
engine.revert()
engine.cleanup()
raise e
engine.cleanup()
# VS
from your_library import DataProcess
from contextlib import contextmanager
@contextmanager
def process_data(engine: DataProcess):
try:
engine.io()
yield engine
except Exception as e:
engine.revert()
raise e
finally:
engine.cleanup()
with process_data(DataProcess()) as engine:
engine.process()
engine.some_more_io()
/r/Python
https://redd.it/1cx0dh4
Reddit
From the Python community on Reddit
Explore this post and more from the Python community
A Beginner's Guide to Unit Testing with Pytest
Hey r/python!
I wrote a guide on how to use Pytest, covering a bunch of important features like designing tests, filtering tests, parameterizing tests, fixtures, and more. Check it out on this link.
/r/Python
https://redd.it/1cwm734
Hey r/python!
I wrote a guide on how to use Pytest, covering a bunch of important features like designing tests, filtering tests, parameterizing tests, fixtures, and more. Check it out on this link.
/r/Python
https://redd.it/1cwm734
Betterstack
A Beginner's Guide to Unit Testing with Pytest | Better Stack Community
Learn how to write clean, concise, and effective Python tests using Pytest's intuitive syntax, fixtures, parametrization, and rich plugin ecosystem
Storing discount info in purchase item as a JSON field or using a separate model?
During the pass few days I've been debating how to best store the discount information in my purchase items.
We allow the users of our marketplace to modify the "Discount" model, for example if they want to change the amount of discount for the same code over time, etc.
Because of this we want to store the actual values that the discount code had at the time of the purchase.
**Option A:** Using a JSON field. In this case we can just create a dictionary with the most important info and store it inside a single field.
class PurchaseItem(models.Model):
...
discount = models.JSONField(null=True, blank=True)
And the discount dictionary would look like this:
{"id": 5, "code": "HELLO10", "type": "vendor", "amount": "32.00", "value": "28.80", "is_fixed": false}
**Option B:** Second option is to create a separate model to store this information, instead of JSON.
class PurchaseItem(models.Model):
...
discount = models.ForeignKey(DiscountApplied, null=True)
class DiscountApplied(BaseModel):
/r/django
https://redd.it/1cx1cmc
During the pass few days I've been debating how to best store the discount information in my purchase items.
We allow the users of our marketplace to modify the "Discount" model, for example if they want to change the amount of discount for the same code over time, etc.
Because of this we want to store the actual values that the discount code had at the time of the purchase.
**Option A:** Using a JSON field. In this case we can just create a dictionary with the most important info and store it inside a single field.
class PurchaseItem(models.Model):
...
discount = models.JSONField(null=True, blank=True)
And the discount dictionary would look like this:
{"id": 5, "code": "HELLO10", "type": "vendor", "amount": "32.00", "value": "28.80", "is_fixed": false}
**Option B:** Second option is to create a separate model to store this information, instead of JSON.
class PurchaseItem(models.Model):
...
discount = models.ForeignKey(DiscountApplied, null=True)
class DiscountApplied(BaseModel):
/r/django
https://redd.it/1cx1cmc
Reddit
From the django community on Reddit
Explore this post and more from the django community
How to demo django project if Github pages can't?
I am a real beginner at code and I've recently been trying to learn new things, django being one of them. How would I showcase my project on future resumes or people if I cannot deploy it on Github pages and I am not willing to pay?
It's probably a stupid question, but do employers have the time to just look at the github repo and run the server
/r/django
https://redd.it/1cwupa9
I am a real beginner at code and I've recently been trying to learn new things, django being one of them. How would I showcase my project on future resumes or people if I cannot deploy it on Github pages and I am not willing to pay?
It's probably a stupid question, but do employers have the time to just look at the github repo and run the server
/r/django
https://redd.it/1cwupa9
Reddit
From the django community on Reddit
Explore this post and more from the django community
How to relate the keys extracted from the API into app.py and index.html
The output on the terminal as part of print statement shows:
{'ticker': 'MARA', 'price': '22.32', 'change\_amount': '2.87', 'change\_percentage': '14.7558%', 'volume': '65114509'}
So ticker, price, change\_amount, change\_percentage are keys.
Now, this is the current app.py:
from flask import Flask, render_template, request
import requests
from sqlalchemy import create_engine, Column, Integer, String, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# Configure Flask app
app = Flask(__name__)
# Configure database connection details (replace with your credentials)
SQLALCHEMY_DATABASE_URI = 'sqlite:///mydatabase.db'
engine = create_engine(SQLALCHEMY_DATABASE_URI)
Base = declarative_base()
# Define database model for storing stock data (optional)
class StockPrice(Base):
__tablename__ = "stock_prices"
id = Column(Integer, primary_key=True)
symbol = Column(String(10), nullable=False)
price = Column(Float, nullable=False)
def __repr__(self):
return
/r/flask
https://redd.it/1cx4vqo
The output on the terminal as part of print statement shows:
{'ticker': 'MARA', 'price': '22.32', 'change\_amount': '2.87', 'change\_percentage': '14.7558%', 'volume': '65114509'}
So ticker, price, change\_amount, change\_percentage are keys.
Now, this is the current app.py:
from flask import Flask, render_template, request
import requests
from sqlalchemy import create_engine, Column, Integer, String, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# Configure Flask app
app = Flask(__name__)
# Configure database connection details (replace with your credentials)
SQLALCHEMY_DATABASE_URI = 'sqlite:///mydatabase.db'
engine = create_engine(SQLALCHEMY_DATABASE_URI)
Base = declarative_base()
# Define database model for storing stock data (optional)
class StockPrice(Base):
__tablename__ = "stock_prices"
id = Column(Integer, primary_key=True)
symbol = Column(String(10), nullable=False)
price = Column(Float, nullable=False)
def __repr__(self):
return
/r/flask
https://redd.it/1cx4vqo
Reddit
From the flask community on Reddit
Explore this post and more from the flask community