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
Single Input for Multiple Model Formset Instances

I'm trying to figure out how I would go about creating a form that has a single multiplechoicefield with Author's name, exactly 9 empty text fields for Book names, and a single save button.

The goal being to select the author once, and add 9 book names to the database. This is relatively straight forward if I use 9 author dropdowns with 9 Book text fields. But how would I go about using a single Author dropdown to populate 9 Book instances?

class Author(models.Model):
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class Book(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)

class BookForm(ModelForm):
class Meta:
model = Book
fields = ['name', 'authors']

def add_two_books(request):
BookFormSet = modelformset_factory(Book, form=BookForm, extra=9)
formset = BookFormSet(request.POST or None, queryset=Author.objects.none())

/r/djangolearning
https://redd.it/8sqzqg
Handling secret keys while sharing repo

Hi there, I've got a bit of stupid question: If I want to create a public django project and hide the secret key and other sensitive information, how do I hide it effectively if I want someone else to be able to run it locally? I mean, if I create a project and then hide its secret key in an env variable on my machine, how do I then allow someone else to run the same project on their machine without putting the secret key in source control?

If I were building a production app I'd just launch on a PAAS provider and set an environment variable on the server in production to be read in with `os.environ.get('SECRET_KEY')`, but in the case of someone cloning my repo they won't have that env variable set. So, how do I get them the key so they can set it, or do they just generate a new one to use in their local development environment somehow?

Thanks!!



/r/django
https://redd.it/8swv3e
Python for Finance?

Hey there, I'm looking to learn financial analysis through python for personal enjoyment/see if I want to pursue it long term. I am an engineering student, decent at python and I understand basic finance/economics, but pretty beginner overall.

Currently, I'm improving my python and finance knowledge concurrently. But I want to see them in action together, and I'm looking for something where I can see how to interact with finance using python, preferably something beginner friendly.

Does anyone have experience with this kinda thing and can make some recommendations?

/r/Python
https://redd.it/8svyjo
How can I present Pandas to my peers?

I am going to hold a seminar on Pandas to my colleagues next week and I am thinking of the best way to introduce the framework and present its most useful features in one hour or little more.

We are all software engineers and we mainly use Java for the backend. We decided to introduce Airflow and Python for wrangling data and producing reports and I was chosen to be a pioneer for this new path so I studied and used Pandas a lot in the last month.

First of all I am wondering what would be more effective for the audience: using a Power Point presentation? or sharing my screen as I pick a dataset and play around with Pandas in a Jupyter notebook?

I am also writing down the topics I think it would be cool to present / demonstrate, such as

* ease of import of a csv or json file
* handling missing data
* groupby, value_counts, aggregation
* features of DateTimeIndex, like selecting by date or by hour of day, resampling, automatic handling of days of the week
* merging two dataframes
* plotting

Do you guys have any suggestions on the best format and what to present?

Thanks!

/r/Python
https://redd.it/8sws81
Made a simple World Cup 2018 Score and Schedule using Selenium webdriver and scraped ESPN World Cup 2018 data

Nothing fancy. Just a simple webscrape using Selenium webdriver and ESPN World Cup 2018 data.

If the game is finished, shows score and who won. If the game has not played yet, shows the scheduled time and date. Also put in flags for each country

[https://github.com/spaceguy01/DataScience/tree/master/ESPN\_World\_Cup\_Score\_Scrape](https://github.com/spaceguy01/DataScience/tree/master/ESPN_World_Cup_Score_Scrape)

If it doesn't show, just click on 'Desktop version' on bottom right

/r/Python
https://redd.it/8sw0h0
AJAX web application. No need for django-webpack-loader, right?

We are trying to build a complex web application - similar to Facebook in some sense. Before we didn't have an API server, so we used the django-webpack-loader and used webpack bundles selectively on Django templates.

Now that we have a full API support for our clients and we are going AJAX for everything, I don't see much value in django-webpack-loader. I am planning to make webpack compile to Django's static directory and then run collectstatic command to push the output files to s3 for CDN.

We are going away with the cached pages because we want a smooth page loading user experience. So the question is, Is there optimization that can be done that I am overlooking here by ditching django-webpack-loader and Django template?

Also if there are hybrid approaches to routing users' page requests via reactJS and Django, please let me know!

/r/django
https://redd.it/8szraj
Help with displaying object data (use a form or not)?

I have a Django app with a list of tiles on a page, where a user can click on tile to view/edit the details behind it. When clicked there is a side bar menu that slides out so the user can still all of the tiles. I initially used an AJAX request to pull the data into divs, but then when I started thinking about how to make it editable using a form just made more sense. However, I'm now starting to wonder though if this is the really the best way to approach this.

One other issue I'm working through is that each tile can have multiple files attached to it. Using the form approach above, I had to add a button that triggers a modal window load with a list of all of the files and then an upload button within that. So what seemed like a better approach a few days ago I feel is now starting to spiral into a mess.

Is displaying the data via a form the right method or not in this situation? If not, how would I go about showing a list of information but making it easily editable (like clicking an edit button)? Any guidance here is appreciated!

/r/django
https://redd.it/8t1fnq
Does anyone have MS in data science?

The more I work, the more I enjoy working with data science. I work in finance, so obviously it has a huge impact. I'm wondering if it's worth getting a MS. I have 20 year experience in system design and consulting, with Bs in CompSci.

What's your experience in MS data science? I'm trying to see if I can do a reputable online master.

Cheers!

/r/Python
https://redd.it/8t1pdb
Python patch, first try.

/r/Python
https://redd.it/8t5ouh
Minimalist BI dashboard with zero configuration

I remember seeing a project that was a perfect match for that description. I think it was written in Python, but don't remember for sure. Now I cannot find it.

I've looked into Bokeh, Dash, Spyre, Bowtie, but none of them comes anywhere close to this description. Basically, I'm not interested in fancy plots and other graphics, just tables will be great. What I'm not interested either is dealing with JavaScript nonsense, writing HTML by hand, and so on. It is not supposed to be a pretty website for marketing. It's a tool for radiologists to run some basic queries against a database, have those queries stored in a form of dashboard and do some basic analysis of the contents of the database. Even Jupyter widgets will be an overkill for that. (Overkill means that the program will not be used / useful).

The project I'm thinking about had a kind of light blue and gray design. As a user, you'd have to specify the database you work with, and then it would present you with a dropdown listing all tables in that database. Selecting a table would launch a screen for creating a query against that table. Once query was created, you'd be able to add it to a dashboard, where you could minimally parametrize the query. A programmer would only need to make sure the database can be accessed by the dashboard, users could do all the rest by themselves, no hand-holding required.

If it helps, I remember seeing it being deployed to Heroku / maybe available as a service from Heroku.

/r/Python
https://redd.it/8t4sy4
A Lightweight version of Djaniero for Sublime Text 3, with Template Comments Fixed

I have been programming Django in Sublime Text 3 for a while, but I always thought the Djaneiro package was way too heavy-handed.

+ I didn't want bulky version-dependent snippets.
+ I didn't want an ST3 view dedicated to "Python (Django)". I'd prefer to treat them as Python code.
+ I wanted to keep syntax highlighting for Django HTML templates. This is the "HTML (Django)" ST3 view.
+ I wanted the Ctrl+/ comment shortcut to work on Django HTML templates. Djaneiro has a 6-year old bug where the wrong comment tag is inserted. (https://github.com/squ1b3r/Djaneiro/issues/10)

So, I cloned the Djaniero plugin and deleted a bunch of the junk I didn't want. I give you `django-highlite`.
https://github.com/ConlanHoldings/django-highlite




/r/django
https://redd.it/8t2udw
Django Rest framework, Django OAuth Toolkit, Token authentication

Hello everyone!

I'm building a api, with authentication token. Took me a few tutorials to figure out how to get a token using postman. I'm only starting the project, there is only 3 models. Now I'm really embarrassed, how do I get the token in the real project? I mean I got it inside postman, I could access a list (json format) of users that are protected by authentications methods. But how to get access to that list in the browser. When I login using my django admin account and try to access the url with a list of users, I don't receive the list, it says "Authentication credentials were not provided." What I need to make to get it? There is something I'm missing here XD. The other models that doesn't require permissions to access, I can access it in the browser and inside postman and it show me the list of objects.

/r/django
https://redd.it/8t5mc2
VS Code not working with Anaconda

Not sure where else to post this but all I want to do is run the libraries and packages installed through anaconda into my root environment through VS Code, the Editor.

Is there a step by step guide?

I've tried the `ctrl + shift + p` and selected my anaconda3\\python.exe environment but it still doesn't recognize the libraries I have installed? I can send exact images if that'd help.

/r/Python
https://redd.it/8t7rq4
Customizing Django Select2 fields

I started using django-select2 with my forms in one of my apps and I am looking for how to customize the form fields.

For example, with one of the form fields you can select a country, so an icon next to the name of the country would be nice.

Also, maybe present the countries in groups like Popular or by continent.

The [Select2](https://select2.org/) site has some examples that I would like to replicate.

On [django-select2 documentation](http://django-select2.readthedocs.io/en/latest/index.html) is not clear on how to do something like that.

Have you ever tried something like this ?

/r/django
https://redd.it/8t8zek