Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
This post has:


Hello! I made a little Program
which gets statistics about this post!
It should be update every 20 seconds.

This post has 654 Upvotes!
-----
It has 81 Downvotes
-----
and 117 comments!
-----

The 3 top comments are from:

1. u/BimphyRedixler

|_Upvotes: 129

|_First word: I

|_Last word: account

2. u/Exodus111

|_Upvotes: 36

|_First word: EditingThisToSeeIfICangeTheFirstWordSetting.

|_Last word: AlsoChangingThisLOL!😂

3. u/CaminoFr

|_Upvotes: 19

|_First word: ",

|_Last word: None

Note: Sometimes theres a Person with lesser upvotes on place 1, If people are disliking comments, the reddit api does weird things!

Second note: The Up/Downvotes and comments are NOT accurate!



Last update: 2021-01-29 18:29:47 CET

total updates: 540


Latest comment by: u/Valtsu0
-----
First word: too
-----
Last word: long
-----

This idea was inspired by u/Krukerfluk
Krukerfluk's post: https://www.reddit.com/r/Python/comments/hoolsm/this_post_has/

My code on Github: https://github.com/Jonathan357611/Reddit-comment-statistics

This program is hosted on a Raspberry pi zero!

/r/Python
https://redd.it/l7u2m3
Made the snake game for the Windows console

It only works in windows because it uses os.system('cls') and a library for getting user keyboard input called msvcrt.

Code

​

https://preview.redd.it/kmzbnq9w87e61.png?width=730&format=png&auto=webp&s=33dfbab4c69bf3466edf36e2eaa8d4254f98dba8

/r/Python
https://redd.it/l7j86b
How to apply not required on model field?

I have a post model that I'm trying to apply not required on image field. Basically, what I'm trying to do is when a user creates a new post, he or she does not need to upload an image. Right now the way it is set up, if image is not uploaded it gives error: "The 'post_image' attribute has no file associated with it" . I tried with blank=True, null=True, but it does not work. What am I missing here? Is there something that I need to do on ModelForm? Any help will be greatly appreciated. Thank you. Here is the code snippet at Pastebin .

/r/django
https://redd.it/l87vr5
How to Deploy Django-React App on Digital Ocean/ AWS?

This will be my first time deployment of django react app.

Facing lots of issue while doing it.

Can some experience hand help me here or atleast point me to the right direction?

Thanks

/r/django
https://redd.it/l8e111
Saturday Daily Thread: Share your resources!

Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?

Use this thread to chat about and share Python resources!

/r/Python
https://redd.it/l88hac
In this tutorial we will automate (with Python) financial analysis and create an Excel sheet from Python. We will use Python to get 10 years of financial statements and use Revenue, Earnings Per Share (EPS) and Free Cash Flow (FCF) to create the Excel sheet to analyze the company.
https://youtu.be/TaF8aPahj1g

/r/Python
https://redd.it/l8f8qo
Contribution For Beginners.

I started Django project, and I am looking to beginners like me to help each other, so check the repo:

link: https://github.com/osamamhd/ivyTasks

/r/django
https://redd.it/l7tqb5
Looking for a good naming convention for user-uploaded media files?

When uploading a media file, for example, an image inside ImageField, you can customize the filename by passing a function to the "upload\_to" argument.

Simplified example:

def rename_image(instance, filename):
return "new_name.jpg"

class Profile(Model):
picture = ImageField(upload_to=rename_image)

​

Assuming that you don't care about the original filename, I can see there are a few options to rename the file:

1. Don't rename it and leave the name as the original file -> "cool pic i took on the seawalk.jpg"
2. Use the ID of the instance you are creating (in this case Profile ID) -> "1.jpg"
3. Use a random unique hash -> "h3gdy652gshj372gs72t7.jpg"
4. Use another related field (for example the username) -> "peter\_steve.jpg"

Not sure if there are other options.

* Option 1 could have name collisions or a huge discrepancy between filenames.
* Option 2 is not possible in many cases since Django doesn't allow to get the ID of an instance that doesn't exist yet.
* Option 4 if the user decides to change his username, the image will now have a different username in the filename (not a big deal but what's

/r/django
https://redd.it/l8iafj
How to successfully deploy Django React App on your Digital Ocean

I have encountered a number of issue while doing the deployment.

Can someone point me to the right direction?

/r/djangolearning
https://redd.it/l8e2o3
I created a video about Neural Networks that is specifically aimed at Python developers! If you understand the Code, you understand how to create a Neural Network from Scratch! The video took me 200h to create and is fully animated! Hope it helps you guys :)
https://youtube.com/watch?v=9RN2Wr8xvro&feature=share

/r/Python
https://redd.it/l8jvev
Many to many relationship?

Hey. So in the past I have used one to one relationships with Flask SQLAlchemy, but I can't seem to wrap my head around many to many. I have three Tables:

* User
* Product
* Order

I need User to have access to Product, and order

I need product to have access to Order and User

I need Order to have access to User and Product

​

class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(255), nullable=False)
password = db.Column(db.String(255), nullable=False)
store_url = db.Column(db.String(200), nullable=True)
activated = db.Column(db.Boolean, default=False, nullable=False)
acc_id = db.Column(db.String(50), nullable=True)

class Product(db.Model):
__tablename__ = 'products'
id = db.Column(db.Integer, primary_key=True)
store_name = db.Column(db.String(255), nullable=False)
item_name = db.Column(db.String(255), nullable=False)


/r/flask
https://redd.it/l8fpfb
Would you be interested in a Django-allauth prettified template ?

When starting a project I usually spend quite some time making the authentication pages provided my Django-allauth looking pretty.

Would there be an interest to make a public repo with “prettified” templates?

Cheers

/r/django
https://redd.it/l8k9gh
I really wanted to learn decorators, so I decided to teach it to force me to understand it more deeply - see my simple guide here: https://pythonhowtoprogram.com/simple-guide-to-decorators-in-python-3-when-and-how-to-use-them/

**https://pythonhowtoprogram.com/simple-guide-to-decorators-in-python-3-when-and-how-to-use-them/**

​

This is how I managed to think about it which was really helpful for me.

https://preview.redd.it/080kpm6h4ie61.png?width=1446&format=png&auto=webp&s=d88f437d02c7732ed070d694c00be6289f238d37

One question I had for the group was what are some use cases where you found decorators to be especially helpful?

For me, it's been (1) performance measurement, (2) ensuring right access rights in flask apps, (3) debugging function calls by having decorator write function call to log files.

/r/Python
https://redd.it/l8q6pm
Jupyter notebook cells in some app idea

I wish to create an app where students can make notes including adding videoclips, images, text etc and also add executable code snippets which work in similar fashion to jupyter notebooks. Is this possible to do? and if so any resources from where I can start

/r/JupyterNotebooks
https://redd.it/l8jck6
Sunday Daily Thread: What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/l8ze6w
The right way to use a ManyToManyField in Django

When you design a database for a large product, it is inevitable to arrive at a point where you have two models that are related to each other in a way that does not get solved using a ForeignKey alone. 

A good example of a many-to-many relationship is the relationship between a sandwich and a sauce. I like a chicken teriyaki sandwich but only if it contains barbeque sauce as well as mayonnaise sauce. So the same sandwich can have multiple sauces. At the same time I want mayonnaise sauce to appear on a turkey sandwich as well, so the same sauce can be used on different kinds of sandwiches.

This is a great place to use the ManyToManyField offered by Django instead of a regular ForeignKey. Unfortunately the way Django deals with this is a bit unintuitive and can be confusing, so I thought it would be best to demonstrate how a many to many relationship works under the hood.

## Many-to-many relationship in a database

To maintain a many-to-many relationship between two tables in a database, the only way is to have a third table which has references to both of those tables. This table is called a “through” table and each

/r/django
https://redd.it/l937f1