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
Model field constraint based on other field value?

Is it somehow possible to add predefined values or constraint (former preferred), based on another field value?

E.g. based on a item transaction type \`RENTAL\` or \`PURCHASE\`, a field indicating \`RENEWAL\` becomes either active or inactive. (meaning when it's active a value is required and when it's inactive, no value is required)

Is it also possible to reflect that logic on forms?

/r/django
https://redd.it/izhcyc
The Jupyter Ecosystem seems vast and overwhelming -- is there a good website or book that distills it?


+ Hosting at Google
+ Hosting at Azure
+ Hosting at Amazon
+ Hosting at MyBinder

-----

If I want to create a series of notebooks that form the basis of an app / website or website / app, but I'd like the website itself to be a static site with the notebooks hosted live elsewhere, what are my options?

/r/JupyterNotebooks
https://redd.it/izh771
I created my First Python package on PyPI : jupyter_timetracker : Time management in a pythonic way.

# Purpose of making
I had always obsessed about saving each and every second of my time in my life. More than just saving, I was more concerned about being able to look at where my time is going throughout the day. The led me to install so many time management app on my mobile, after a lot of trial and error, I found atimelogger the best. It has all the capability what I was looking for. However, later it started to provide only basic features in free version and asking to pay to upgrade to have full features. Also, it has no desktop app. I found helpless in situations, where I am on desktop and away from my mobile. That led me to search for more productive and free apps that were both for mobile and desktop. Then i got to know about toggl and timecamp. However, these sites also provide very minimal features for free and require to pay for all features.

As an introvert guy, I want to know deeply about myself ( self-introspection ). So apart from just logging time and having timesheet, I want to

/r/Python
https://redd.it/izop7a
flask sqlalchecmy db.relationship column is not created

hello everyone, when i execute `db.create_all()` all columns gets created just fine except for one column:

products = db.relationship('Product', backref='owner', lazy=True)

here is the models

class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
city = db.Column(db.String(20), nullable=False)
branch = db.Column(db.String(20), nullable=False)
username = db.Column(db.String(20), unique=True, nullable=False)
products = db.relationship('Product', backref='owner', lazy=True)


class Product(db.Model):
id = db.Column(db.Integer, primary_key=True)
productName = db.Column(db.String(50))
productCode = db.Column(db.String(200))
productDescription = db.Column(db.String(50))
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

it was working just fine i don't know what went wrong

here is how i created the tables

>>from root import db, create_app
>>db.create_all(app=create_app())

i also tried:

>>from root import db, create_app
>>from root.users.models import User
>>from root.api.models import Product


/r/flask
https://redd.it/izjahf
Im starting a job in django

Hey guys!

In one week i will start mi first job as a dev with django + angular/react.

I just learn the django basics, can anyone give me some noobie advice?

thanks a lot!

/r/django
https://redd.it/izir65
[P] The Last Machine & Deep-Learning Compendium You’ll Ever Need

**TL;DR –** [Go to The Compendium](https://towardsdatascience.com/the-last-machine-deep-learning-compendium-youll-ever-need-dc973643c4e1) – This is a curated ***\~330*** page document, with resources on almost any Data Science and ML topic you can probably imagine.

***Disclaimer:*** This is not my project, but a friend's.

I know medium posts are not exactly projects – but this one should count as one.

It is an incredible resource created over a very long period of time – it has literally hundreds of pages with links and summaries on almost any topic in DS, ML, DL you can think of (using CTRL+F is a huge pleasure). It is still being maintained, by someone that has real life experience in the industry and academic research....also, if you want [you can go directly to the Google Doc itself](https://docs.google.com/document/d/1wvtcwc8LOb3PZI9huQOD7UjqUoY98N5r3aQsWKNAlzk/edit?usp=sharing).

I think this would be a great resource for many people in the community, and this might be a good place to share additional awesome curated resources.

/r/MachineLearning
https://redd.it/izh8a7
Question regarding nested serializers

I'm building an API for a web application that I'm working on where I'm using a nested relationship for a create end point like the one here in the DRF framework

​

[https://www.django-rest-framework.org/api-guide/relations/#nested-relationships](https://www.django-rest-framework.org/api-guide/relations/#nested-relationships)

​

I want to use the serializer for updating, so I'm using a code like this:

def update(self, instance, validated_data):
tracks_data = validated_data.pop('tracks')
tracks = instance.tracks.all()
tracks = list(tracks)
instance.album_name = validated_data.get('album_name', instance.album_name)
instance.artist = validated_data.get('artist', instance.artist)
instance.save()

for track_data in tracks_data:
track = tracks.pop(0)
track.order = track_data.get('order', track.order)
track.title = track_data.get('title', track.title)
track.duration = track_data.get('duration', track.duration)
track.save()


/r/django
https://redd.it/izozan
My open-source website built with Flask. You can convert audio and video files to another format, or download YouTube videos.

https://free-av-tools.com

Source code can be found on my GitHub page, GitHub.com/BassThatHertz

Feedback is welcome, whether it's regarding the website itself or the code. I'm not a Python expert, it was my first programming language which I started learning around Jan 2019 and I've been using it on-and-off since then. I had to learn Flask and JavaScript to make this website.

/r/flask
https://redd.it/izv8gd
Saturday megathread: 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/izv3tl
This media is not supported in your browser
VIEW IN TELEGRAM
I made an Instagram Bot to make DeepFakes for everyone! @deepfake.maker

/r/Python
https://redd.it/izspe0
I made a Python bot that scrapes Udemy Coupons and then AUTOMATICALLY ENROLLS YOU to those PAID COURSES for FREE. Check out the GitHub below to get the code! :) Do Star & Fork the repository if you like it!

Get and fork the code here: [https://github.com/aapatre/Automatic-Udemy-Course-Enroller-GET-PAID-UDEMY-COURSES-for-FREE](https://github.com/aapatre/Automatic-Udemy-Course-Enroller-GET-PAID-UDEMY-COURSES-for-FREE)

Watch the bot in action here: [https://www.youtube.com/watch?v=IW8CCtv2k2A](https://www.youtube.com/watch?v=IW8CCtv2k2A)

/r/Python
https://redd.it/izrjbc
Issue with installing Django Debug Toolbar

Hi guys,
Im following a small clone project to create a Youtube-like website, but i am stuck on the part where i have to install django debug toolbar.

​

1. I have installed the necessary packages via pip
2. I have gone precisely through the documentation for DJDT - modified [settings.py](https://settings.py) accordingly, urls
3. I have added [127.0.0.1](https://127.0.0.1) as ALLOWED\_IPS in [settings.py](https://settings.py)

When i run the server i get these messages in the console:

​

`[26/Sep/2020 16:08:22] "GET /admin/ HTTP/1.1" 200 13217`

`[26/Sep/2020 16:08:22] "GET /static/debug_toolbar/css/toolbar.css HTTP/1.1" 304 0`

`[26/Sep/2020 16:08:22] "GET /static/debug_toolbar/img/ajax-loader.gif HTTP/1.1" 304 0`

`[26/Sep/2020 16:08:22] "GET /static/debug_toolbar/js/toolbar.js HTTP/1.1" 304 0`

`[26/Sep/2020 16:08:22] "GET /admin/ HTTP/1.1" 200 13217`

`[26/Sep/2020 16:08:22] "GET /static/debug_toolbar/css/print.css HTTP/1.1" 304 0`

​

Then i check the admin page and the toolbar isnt there.

I've inspected the site and sure enough it seems like the toolbar should be there, its showing me the divs and all.

There is only one error:

`Failed to load module script: toolbar.js The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.`

​

Here is my [urls.py](https://urls.py) file:

​



`from django.contrib import admin`
`from django.urls import path`
`from django.conf import settings`
`from django.conf.urls import include, url`
`from django.urls import include, path`
`urlpatterns = [`
    `path('admin/',admin.site.urls),`
`]`
`if settings.DEBUG:`
`import debug_toolbar`
    `urlpatterns += [`
        `url(r'^__debug__/', include(debug_toolbar.urls)),`
    `]`

/r/djangolearning
https://redd.it/j06t49
State in Flask

Hi all, I’m new to Flask and I’m on a small web app project where users are supposed to make repetitive crud operation and some calculation server side, on the same objects. Now I don’t know if it is possible or neither if I’m thinking the right way, but I’d like to cache the state of the objects, to avoid quering each time the db, create the object and (when the user simply reads data) iterate again the list and send it back as a json. Being Flask thread safe, it seems impossible and neither right to work this way. Can anyone give me advice if there is any solution or if I’m taking the problem in the wrong way?

/r/flask
https://redd.it/j0ardw
Hello from .NET!

Just wanted to drop in and say hi! I've been a .NET developer for over 20 years and have been embarking on a journey with AWS for the last several years, but have struggled a bit with the .NET eco system within that context, more specifically, the serverless stuff. I recently discovered Python/boto and must say I am totally in love! Python just seems so much easier and requires way less code to do powerful stuff. I also appreciate the dynamic nature of it. Coming from a statically typed language is a breath of fresh air.

It also seems there is a very robust community around Python, not to mention a TON more jobs than .NET. Looking forward to getting more involved.

/r/Python
https://redd.it/j0b2lq
Why you should try VizTracer to understand your python program

Have you ever thought about "why is my program doing this thing" when you are developing? That happens to me quite a lot when I'm working with Python, and becomes the reason I built [VizTracer](https://github.com/gaogaotiantian/viztracer).

VizTracer is helpful in many aspects, debugging, logging or profiling. The fundamental idea behind VizTracer is to help you understand what your program is doing.

Unlike traditional debuggers, which normally pin you at a specific time and allows you to check on variables, VizTracer focuses on the call stack over time. Basically, VizTracer visualizes how functions calls each other while your program is running.

[Recursive Fibonacci ](https://preview.redd.it/6g55u869pjp51.png?width=2286&format=png&auto=webp&s=bdf8148c457bfc8306333a2db7a3ea808b469b05)

This is a very simple example, the program is doing a recursive fibonacci number calculation:

def fib(n):
if n < 2:
return 1
return fib(n-1) + fib(n-2)

VizTracer can show how the recursive function actually works.

VizTracer is not a toy, it can also deal with very large program.

[Monte Carlo Tree Search](https://preview.redd.it/1jy7ttqxpjp51.png?width=2282&format=png&auto=webp&s=91ae66cc28a050e152d43a783648a0cb1ebdab40)

Above is the result of a MCTS(Monte Carlo Tree Search). You can zoom in to check the details of the program

[Details

/r/Python
https://redd.it/j0dj8q
Sunday megathread: 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/j0gs61
I Wrote a Script to notify Me of any Instagram Unfollowers

[https://www.youtube.com/watch?v=2R0VogObeT4](https://www.youtube.com/watch?v=2R0VogObeT4)

If you've ever been unfollowed you've probably wondered... "hmm, I wonder who that was"

With this script, now you'll be notified automatically

[https://github.com/yyildiz/instagram-fake-friend-finder](https://github.com/yyildiz/instagram-fake-friend-finder)

/r/Python
https://redd.it/j0cgib