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
Good Django training resources for experienced developers in other languages?

I'm having a hard time finding django training resources geared towards people who already have experience with other languages / frameworks such as PHP/Symfony or Ruby. Does anyone have any recommendations?

Paid or free courses / books are would be fine... But bonus if something covers building apis with DRF...

/r/django
https://redd.it/6z1jzp
Slack CLI for productive developers

I just released v2.0.0 of my [slack-cli](https://pypi.org/project/slack-cli/) python package. Comments are welcome!

(also, this is my first ever reddit post \o/)

EDIT: missing link damn it

/r/Python
https://redd.it/6z1jt3
Trying to build a date based app

Hi guys,

I'm trying to build an app where I can consult all of my swimming sessions. Every time I go swimming I upload the data from the watch to a mariadb database, adding one column with the date of the session like 2017-09-09.

Now I'm trying to build a django app where I can see the sessions organized by date. Like /2017/ shows all the sessions of this year, /2017/sep/ shows this month sessions, and /2017/sep/09 the data for this session.

This is my urls.py

url(r'^(?P<year_slug>[0-9]{4})/$', views.by_year, name='by_year'),
url(r'^(?P<year_slug>[0-9]{4})/(?P<month_slug>[\w-]+)/$', views.by_month, name='by_month'),
url(r'^(?P<year_slug>[0-9]{4})/(?P<month_slug>[\w-]+)/(?P<day_slug>[\w-]+)/$', views.by_day, name='by_day'),

I already kind of made it, I added three ForeignKey to my sessions model, pointing to Year, Month, and Day. Then I added three column to the database and added the value for each one, like if it's in 2017 it will be a 1, if it's in 2018 it's gonna be a two, and so on for months and days.

I feel like this is far from optimal. Can't I do that by using the 2017-09-09 which is in the date column, instead of adding three tables to the database?

Or is there even a totally different way to achieve this? (I tried {Year,Month,Day}ArchiveView but I wasn't able to make my own queries (like to get the total distance for one month)

My second question is, even if I go that way, I'm able to display the total distance for august in 2017/08/ by using the month_slug, but how can I do that in /2017/ ? I mean I understand I can't use the month_slug, but since I have sessions classed by month using {% ifchanged %}, isn't it possible to display the total distance for each month ?


I would appreciate some help here, thanks in advance and sorry for the wall of text.

/r/django
https://redd.it/6z3qxs
Detailed Flask Web Development Series

Hey guys,

I’ve been working on building a really detailed course around the Flask framework to get many beginners started with web development with Python.

Course Page: https://www.thecodewolf.com/courses/python-flask-web-development/

Here are the first few videos of the series, I’ve also have written tutorials with the videos as well:

* Overview & Installation
* [Video](https://youtu.be/Ty2qAlDsAxc)
* [Blog Post](https://www.thecodewolf.com/introduction-to-python-flask-web-development-overview-of-flask/)
* Hello World & Flask Application Structure
* [Video](https://youtu.be/OrTWfZpv0i0)
* [Blog Post](https://www.thecodewolf.com/python-flask-web-development-hello-world-flask-application-structure/)
* Flask Templates, Jinja2 Tutorial, Bootstrap Integration, and Custom Error Pages
* [Video](https://youtu.be/0M74EGmqWIY)
* [Blog Post](https://www.thecodewolf.com/python-flask-web-development-flask-templates-and-flask-bootstrap-integration/)

The next few videos and guides will be coming out in the next few days/weeks, and I’ll be releasing new content on a regular basis.

**My goal is to create the best foundational web development course with the Flask framework to get as many people started with Flask as a stepping stone in web development with Python.**

If you guys enjoy the content, I will also be working on a detailed series like this with Django as well.

Here are some of the following videos that will be coming up with the series:

* Web Forms with Flask
* Database Integrations with Flask

Then I will be working on content that will actually have you build a complete blog application with users, blog posts, and all sorts of other really cool stuff.

With the current content so far, I would love to hear some feedback as well.

~ CW

/r/Python
https://redd.it/6z5jkx
I wrote a library that automatically formats help messages for your program and integrates with Sphinx. Feedback is greatly appreciated :-)
https://github.com/lostatc/linotype

/r/Python
https://redd.it/6z3wfz
Why create more than one url files?

So i'd like to began by saying i'm a total noob in django and web development. I started taking the trydjango1.11 series available on youtube. It's well taught and explained.

In the series, they only configure the urls in the root folder of our projec where the main url file is located. The other day i was browsing other people's tutorials and django's documents and i noticed that they made two url files. The one which was already available in the project folder, and the other they made in their app's folder.

I don't understand the point of this. The series i'm watching works perfectly with only one url file which is in the root of the project's folder.

As english is not my first language, i hope you could understand my question. Any sort of help is appreciated :)

/r/djangolearning
https://redd.it/6z0kdd
When creating a "Vote" system should you store count or is subtracting downvotes from upvotes fine?

I'm looking to create a basic voting system for some objects. My model looks like:

class Model(models.Model):

obj = models.ForeignKey('obj.Obj')
user = models.ForeignKey('users.User')

upvotes = models.PositiveIntegerField(default=0)
downvotes = models.PositiveIntegerField(default=0)
count = models.IntegerField(default=0)

I was just wondering do i need the `count` field or could i just rely on using something like


@cached_property
def count(self):
return self.upvotes - self.downvotes

If i should store a count field, why is that?

/r/django
https://redd.it/6z3wh6
Help with adding javascript to django templates

Today was my first attempt at adding javascript to a django template. I've tried to load the javascript in my base template, then I included a bunch of script inside another template. Part of the base.html is as follows, it is generally working because I know that my css files get loaded:

<!DOCTYPE html>
<html lang="en">
{% block head %}<head>{% load static %}

<meta charset="utf-8">

<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="{% static "css/normalize.css" %}">
<link rel="stylesheet" href="{% static "css/skeleton.css" %}">
<link rel="stylesheet" href="{% static "css/layout.css" %}">

<!-- JAVASCRIPT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<script type="text/javascript" language="Javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.11.3.min.js"></script>

</head>
{% endblock %}


And here is the template that is supposed to have the javascript working:

{% extends 'classroom/base.html' %}
{% block body %}
<div class="container">
<div class="row">
<div class="twelve columns">
<h1>Choose the block</h1>
</div>
</div>

<div class="row">
<div class="twelve columns">
{{ classroom.id }}
<form action="{% url 'classroom:random' %}" method="get">
<select name="class_block">
{% for room in classroom %}
<option value={{ room.course_block }}>{{ room.get_course_block_display }}</option>
{% endfor %}
</select>
<input type="submit" value="submit" />
</form>
</div>
</div>
<div class="row">
<div class="one-third columns">
test
{% for s in students %}
<ul>
<li>{{ s.nickname }}</li>
</ul>
{% endfor %}
</div>
</div>
<div class="row">
<div class="twelve columns">
<script>
var nameArray = [
"Jimmy",
"Sonny",
"Sammy",
"Henry",
"Hank",
"Susan",
"Sebby",
"Alyssa",
"Pepper",
"Ken",
"Steve",
"Kandi",
"Wes"
];
var numberStudents = nameArray.length;
var interval;

for(n = 0; n < numberStudents; n++){
var divName = "floatName" + n;
console.log(divName);
var names = nameArray[n];
var divTag = document.createElement('div');
divTag.id = divName;
divTag.innerHTML = names;
divTag.style.position = "absolute";
divTag.style.top = 50 + n*20 + "px";
divTag.style.left = "50px";
divTag.className = "randomFloat";
document.body.appendChild(divTag);
};
var loopAllowed = false;
$( "#go" ).click(function() {
loopAllowed = true;
var max = 12;
var loop = function(){
for(i = 0; i < (numberStudents + 1); i++){
var divName = "floatName" + i;
console.log(divName);
$( "#" + divName ).animate({
left: Math.random()*500 + "px",
top: Math.random()*500 + "px"
}, 500, i == max - 1 && loopAllowed ? loop : undefined);
}
};
loop();
});

$( "#stop" ).click(function() {
loopAllowed = false;
});

</script>
</div>
</div>
</div>
{% endblock %}

The parts inside <script></script> work when its loaded into a browser on its own. Inside this template though, nothing is happening.

/r/django
https://redd.it/6z38c1
Auto setting a thumbnail to an album model

Hey guys,

I'm working on a project where I have photo albums and each album has it's pictures (with a ForeignKey to the album model). How can I pull the first image of the album and set it as the thumbnail of the album?

I'm thinking about setting up a view function that checks if there are any images in the model, and if there is, it pulls one of these images and defines it as a thumb. But I'm not sure how to do it exactly.

/r/django
https://redd.it/6z24dj
We are the Google Brain team. We’d love to answer your questions (again)

We had so much fun at our [2016 AMA](https://www.reddit.com/r/MachineLearning/comments/4w6tsv/ama_we_are_the_google_brain_team_wed_love_to/) that we’re back again!

We are a group of research scientists and engineers that work on the Google Brain team. You can learn more about us and our work at [g.co/brain](http://g.co/brain), including a [list of our publications](https://research.google.com/pubs/BrainTeam.html), our [blog posts](https://research.googleblog.com/search/label/Google%20Brain), our [team's mission and culture](https://research.google.com/teams/brain/about.html), some of our particular areas of research, and can read about the experiences of our first cohort of [Google Brain Residents](http://g.co/brainresidency) who “graduated” in June of 2017.

You can also learn more about the TensorFlow system that our group open-sourced at [tensorflow.org](http://tensorflow.org) in November, 2015. In less than two years since its open-source release, TensorFlow has attracted a vibrant community of developers, machine learning researchers and practitioners from all across the globe.

We’re excited to talk to you about our work, including topics like creating machines that [learn how to learn](https://research.google.com/pubs/pub45826.html), enabling people to [explore deep learning right in their browsers](https://research.googleblog.com/2017/08/harness-power-of-machine-learning-in.html), Google's custom machine learning TPU chips and systems ([TPUv1](https://arxiv.org/abs/1704.04760) and [TPUv2](http://g.co/tpu)), use of machine learning for [robotics](http://g.co/brain/robotics) and [healthcare](http://g.co/brain/healthcare), our papers accepted to [ICLR 2017](https://research.googleblog.com/2017/04/research-at-google-and-iclr-2017.html), [ICML 2017](https://research.googleblog.com/2017/08/google-at-icml-2017.html) and NIPS 2017 (public list to be posted soon), and anything else you all want to discuss.

We're posting this a few days early to collect your questions here, and we’ll be online for much of the day on September 13, 2017, starting at around 9 AM PDT to answer your questions.


/r/MachineLearning
https://redd.it/6z51xb
OLS model in Python; how to find correlation between gender and 20 specific diseases?

Apologies for the bad explanations, I am really confused and clueless.

As the title states, I am trying to find the correlation but I am having some difficulties with the work before running the model.

I have male, female, 20 different diseases "as the columns" and patients on the rows. I have "dummied" it down to 0.0 or 1.0,
ex:

Male Female D1 D2

P1 0.0 , 1.0 , 0.0 , 1.0

P1 is female with disease D2.

I want to use the model to find which disease(s) have a higher correlation to males.

Now I am clueless to the steps to find the correlation....For the first time, I would appreciate answers which is "dummyed" down for me hehehe

/r/pystats
https://redd.it/6z8tyl
How do you distribute your app?

I finally made my way to finalize the first version of my web app! Now the question I'm struggling with is: how do I distribute it?

The app (Django + Django Rest Framowork + client with tons of JS) is of the "final product" type (not a Django reusable app) with, obviously, dependencies. It is supposed to be simply deployed on a host and served by a HTTP server.

When I deploy a PHP web app on a server, I am used to deal with a single archive containing all the necessary files. I thought it'd be the same for a Django app, but I don't know how to handle the dependencies.

So far, the suggestions I've read are the following:

* Create a Docker container. Seems neat, but a bit overkill;
* Create a system package (RPM, DEB). Still overkill;
* Create a Python package with setuptools. Many posts on SO suggest to go this way. Why? For me, it doesn't make sense: as I said, the app is a "final product," there is no point to install it as a regular package (nor point to import it in another project). Moreover, dependencies are not included in the archive. And, if installed, how do I edit local settings?
* Create a all-in-one Python package with PyInstaller. Seems overkill as Python should be available on a server. And I had a hard time to get it working;
* Do nothing, just create an archive of the repo, with no dependencies, and put documentation to set the project up.

I'm very perplex. What should I do?

/r/django
https://redd.it/6zbdi8
DjangoCon 2017 Videos are up and a question!

Firstly, I know a lot of people have been waiting, but the [recordings from DjangoCon 2017 are finally up!](https://www.youtube.com/channel/UC0yY6a79pPY9J0ShIHRf6yw/videos)

Secondly, I want to know from you, the community, what would you like to see covered next year?

/r/djangolearning
https://redd.it/6yio0r
Extract data from invoices?

Hi, I’m trying to automate some tedious parts of my work but I don’t know exactly how to go about doing so.

I get a lot of invoices from several companies who all have different designs and types, some will be an excel spreadsheet converted to a pdf and some will be a scanned document, but I need to extract some information from them.

I don’t need all the data from the invoices and there are certain areas where the data is or certain keywords I could use to find the data.

What would be the best way to go about doing this?

/r/Python
https://redd.it/6zd6ui