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
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
reddit
r/djangolearning - Single Input for Multiple Model Formset Instances
2 votes and 3 so far on reddit
Writing Python Extensions In Rust Using PyO3
https://www.benfrederickson.com/writing-python-extensions-in-rust-using-pyo3/
/r/Python
https://redd.it/8svfkz
https://www.benfrederickson.com/writing-python-extensions-in-rust-using-pyo3/
/r/Python
https://redd.it/8svfkz
Benfrederickson
Writing Python Extensions In Rust Using PyO3
GeoPandas and pandas.HDFStore() method incompatible.
https://www.reddit.com/r/gis/comments/8stckr/geopandas_and_pandashdfstore_method_incompatible/
/r/pystats
https://redd.it/8stg6r
https://www.reddit.com/r/gis/comments/8stckr/geopandas_and_pandashdfstore_method_incompatible/
/r/pystats
https://redd.it/8stg6r
reddit
r/gis - GeoPandas and pandas.HDFStore() method incompatible.
2 votes and 1 so far on reddit
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
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
reddit
r/django - Handling secret keys while sharing repo
1 votes and 2 so far on reddit
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
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
reddit
r/Python - Python for Finance?
12 votes and 9 so far on reddit
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
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
reddit
r/Python - How can I present Pandas to my peers?
7 votes and 8 so far on reddit
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
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
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
reddit
r/django - AJAX web application. No need for django-webpack-loader, right?
2 votes and 0 so far on reddit
Install and Configure – Django Virtualenv, Gunicorn, Nginx and Supervisor | All in one Article!
https://opensourceprojects.org/install-and-configure-django-virtualenv-gunicorn-nginx-and-supervisor/
/r/Python
https://redd.it/8sz9qu
https://opensourceprojects.org/install-and-configure-django-virtualenv-gunicorn-nginx-and-supervisor/
/r/Python
https://redd.it/8sz9qu
opensourceprojects.org
Install and Configure – Django Virtualenv, Gunicorn, Nginx and Supervisor | Open Source Projects - Learn Python
Hi, in this article we will create a Virtualenv, then create a django project in Virtualenv, how to run this project on gunicorn. We will talk about how to talk - Open Source Projects - Learn Python
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
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
reddit
r/django - Help with displaying object data (use a form or not)?
1 votes and 0 so far on reddit
I made a timelapse of me making a simple game in pyglet after 2 days of learning it
https://www.youtube.com/watch?v=XLFabo0IVho
/r/Python
https://redd.it/8t0esv
https://www.youtube.com/watch?v=XLFabo0IVho
/r/Python
https://redd.it/8t0esv
YouTube
I created a simple game from scratch using Python - timelapse
Hi there! This is the first video from my programming series called Random Python. In this video I used for the first time the pyglet library to create a project. Previously I used p5.js and p5py to create graphics so I learned how to draw things on screen…
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
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
reddit
r/Python - Does anyone have MS in data science?
3 votes and 4 so far on reddit
Docker Usage in 'The Flask Mega-Tutorial' by Miguel Grinberg - A Review
https://vsupalov.com/flask-megatutorial-review/
/r/flask
https://redd.it/8sytzh
https://vsupalov.com/flask-megatutorial-review/
/r/flask
https://redd.it/8sytzh
vsupalov.com
Docker Usage in 'The Flask Mega-Tutorial' by Miguel Grinberg - A Review
How to make an iterator in Python
http://treyhunner.com/2018/06/how-to-make-an-iterator-in-python/
/r/Python
https://redd.it/8t3gtj
http://treyhunner.com/2018/06/how-to-make-an-iterator-in-python/
/r/Python
https://redd.it/8t3gtj
Treyhunner
How to make an iterator in Python
I wrote an article sometime ago on the iterator protocol that powers Python’s for loops.
One thing I left out of that article was how to make …
One thing I left out of that article was how to make …
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
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
reddit
r/Python - Minimalist BI dashboard with zero configuration
6 votes and 3 so far on reddit
New Python website - pythoncheatsheet.org
[www.pythoncheatsheet.org](https://www.pythoncheatsheet.org) \- The idea is to have an easy to use cheat sheet... I hope it can help someone else besides me.
If you like it, don't forget to check on how to [contribute](https://www.pythoncheatsheet.org/contribute)!
/r/Python
https://redd.it/8t7t16
[www.pythoncheatsheet.org](https://www.pythoncheatsheet.org) \- The idea is to have an easy to use cheat sheet... I hope it can help someone else besides me.
If you like it, don't forget to check on how to [contribute](https://www.pythoncheatsheet.org/contribute)!
/r/Python
https://redd.it/8t7t16
pythoncheatsheet.org
Python Cheat Sheet – Free, Beginner-Friendly Guide with Labs & PDF
The most complete Python cheat sheet online. Learn step-by-step with interactive labs, download free PDF cheat sheets, and explore beginner-friendly Python guides.
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
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
GitHub
Commenting on Django Templates incorrect #10
When the shortcut for commenting is pressed (Command - / ), comments are presented as standard HTML, rather than Django templates (as with the TextMate bundle).
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
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
reddit
r/django - Django Rest framework, Django OAuth Toolkit, Token authentication
2 votes and 1 so far on reddit
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
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
reddit
r/Python - VS Code not working with Anaconda
4 votes and 2 so far on reddit
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
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
select2.org
Getting Started | Select2 - The jQuery replacement for select boxes
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and pagination (infinite scrolling) of results.