Help with query: how to filter objects based on boolean attribute on model with ForeignKey to that object?
Have a User Profile model with OneToOneField to User and given profiles:
`profiles = Profile.objects.filter(has_car=True, user__age__gt=30)`
Now want to only show profiles where user has verified EmailAddres in Allauth. I think a given User can have multiple EmailAddresses that are verified.
class EmailAddress(models.Model):
user = models.ForeignKey(allauth_app_settings.USER_MODEL)
email = models.EmailField(unique=app_settings.UNIQUE_EMAIL)
verified = models.BooleanField(default=False)
primary = models.BooleanField(default=False)
So how can I filter profiles to only show users where user has at least one EmailAddress with verified=True? Obviously one way would be to just iterate over profiles:
profile_set = []
for profile in profiles:
if profile.user.emailaddress_set.first().verified:
profile_set.add(profile)
This just is inefficient, especially for thousands of profiles. Any suggestions? Thanks all.
/r/django
https://redd.it/aws4rd
Have a User Profile model with OneToOneField to User and given profiles:
`profiles = Profile.objects.filter(has_car=True, user__age__gt=30)`
Now want to only show profiles where user has verified EmailAddres in Allauth. I think a given User can have multiple EmailAddresses that are verified.
class EmailAddress(models.Model):
user = models.ForeignKey(allauth_app_settings.USER_MODEL)
email = models.EmailField(unique=app_settings.UNIQUE_EMAIL)
verified = models.BooleanField(default=False)
primary = models.BooleanField(default=False)
So how can I filter profiles to only show users where user has at least one EmailAddress with verified=True? Obviously one way would be to just iterate over profiles:
profile_set = []
for profile in profiles:
if profile.user.emailaddress_set.first().verified:
profile_set.add(profile)
This just is inefficient, especially for thousands of profiles. Any suggestions? Thanks all.
/r/django
https://redd.it/aws4rd
reddit
r/django - Help with query: how to filter objects based on boolean attribute on model with ForeignKey to that object?
0 votes and 0 comments so far on Reddit
I recorded a 6-part series on DataClasses, explaining all the important concepts. Have you started using dataclasses yet?
https://www.youtube.com/watch?v=2CvzoNPSOHg&list=PLyb_C2HpOQSAQe8VOY9FbZXR_OLhaNpi4
/r/Python
https://redd.it/awr1go
https://www.youtube.com/watch?v=2CvzoNPSOHg&list=PLyb_C2HpOQSAQe8VOY9FbZXR_OLhaNpi4
/r/Python
https://redd.it/awr1go
YouTube
Dataclasses in Python (Part-1) | Introduction
Welcome the first video of the series "Dataclasses in Python".
This video gives a brief overview of the scenarios where we may need dataclasses and how to use them in the simplest way possible.
Type hinting in Python: https://www.youtube.com/watch?v=1psWpWml_VE…
This video gives a brief overview of the scenarios where we may need dataclasses and how to use them in the simplest way possible.
Type hinting in Python: https://www.youtube.com/watch?v=1psWpWml_VE…
Raw SQL usage in Django
Hi everyone.
As we know, django orm each release has a good performance improvement and nice feature until now.
I just need your opinion, when you decide to use raw SQL?
Personally, I never use raw SQL due to orm is more maintainable to me.
/r/django
https://redd.it/awusjs
Hi everyone.
As we know, django orm each release has a good performance improvement and nice feature until now.
I just need your opinion, when you decide to use raw SQL?
Personally, I never use raw SQL due to orm is more maintainable to me.
/r/django
https://redd.it/awusjs
reddit
r/django - Raw SQL usage in Django
0 votes and 1 comment so far on Reddit
A Python utility for analyzing a given solution to the Einstein field equations.
I wanted to share with the community an open source python package I had been developing since November. It is called Spacetime Engine.
[github.com/spacetimeengineer/spacetimeengine](https://github.com/spacetimeengineer/spacetimeengine)
My name is Michael. I am a physicist who works as an engineer. My story is that in October 2018 I was preparing to submit my first physics publication, which reviewed a particular cosmological model that I had been working with for some time. I was at the point where I had completed all of my research and was fully prepared. The only problem was that at the time I felt concerned that I may have made some mistakes which went unnoticed, so I decided to write a computer algebra software to check the veracity of my solutions so that I could feel confident in my results. After using this new utility, I realized I had made some fairly significant errors in my approach, and so the software apparently did it’s job. At first I was quite frustrated because I had put a significant amount of time into this solution, but I realized I had a new ability to correct my own errors and expand upon what I already knew. I was now able to study
/r/Python
https://redd.it/awtry9
I wanted to share with the community an open source python package I had been developing since November. It is called Spacetime Engine.
[github.com/spacetimeengineer/spacetimeengine](https://github.com/spacetimeengineer/spacetimeengine)
My name is Michael. I am a physicist who works as an engineer. My story is that in October 2018 I was preparing to submit my first physics publication, which reviewed a particular cosmological model that I had been working with for some time. I was at the point where I had completed all of my research and was fully prepared. The only problem was that at the time I felt concerned that I may have made some mistakes which went unnoticed, so I decided to write a computer algebra software to check the veracity of my solutions so that I could feel confident in my results. After using this new utility, I realized I had made some fairly significant errors in my approach, and so the software apparently did it’s job. At first I was quite frustrated because I had put a significant amount of time into this solution, but I realized I had a new ability to correct my own errors and expand upon what I already knew. I was now able to study
/r/Python
https://redd.it/awtry9
GitHub
GitHub - spacetimeengineer/spacetimeengine: A Python utility for analyzing a given solution to the Einstein's field equations.…
A Python utility for analyzing a given solution to the Einstein's field equations. Built on Sympy. - spacetimeengineer/spacetimeengine
The Simplest Guide to Python Logging with Clear Explanations and Practice Exercises
https://www.machinelearningplus.com/python/python-logging-guide/
/r/Python
https://redd.it/awtip9
https://www.machinelearningplus.com/python/python-logging-guide/
/r/Python
https://redd.it/awtip9
Machine Learning Plus
Python Logging – Simplest Guide with Full Code and Examples
Learn Complete Data Science Online
Any tutorial or guide for Social Authentication using django rest-auth and vuejs?
I'm trying to implement social app authentication using vuejs as front end but since it's the first time I'm doing it and am also not so familiar with vuejs, can anyone guide me through the process? Thank you all in advance. I've managed to implement rest-auth properly but now that I'm using the front end, I'm kind of lost and don't know
​
I have not been able to find a lot of helpful content to guide me. This is the first time I'm dealing with APIs in general. Any help would be appreciated. Thanks.
/r/django
https://redd.it/awwp7q
I'm trying to implement social app authentication using vuejs as front end but since it's the first time I'm doing it and am also not so familiar with vuejs, can anyone guide me through the process? Thank you all in advance. I've managed to implement rest-auth properly but now that I'm using the front end, I'm kind of lost and don't know
​
I have not been able to find a lot of helpful content to guide me. This is the first time I'm dealing with APIs in general. Any help would be appreciated. Thanks.
/r/django
https://redd.it/awwp7q
reddit
r/django - Any tutorial or guide for Social Authentication using django rest-auth and vuejs?
0 votes and 0 comments so far on Reddit
How to make scripts usable by non CLI users
I think this is a common problem for developers who like to create great CLI applications. How do you make it usable by your grandpa? Or by anyone whom the functionality of the script is useful but won't ever pop up a cli and type those commands.
Let's say I have a script that would do a simple task. Something that I could probably run as:
```
$ ./script --file /home/my/file.txt
```
Only ways I could think of how non CLI users can use this are the following:
* make a GUI - everyone knows a GUI and knows how to use a file chooser.
* wrap your python script in an executable (bat file maybe) and provide user prompts for the filename (they'd need to type in really long names though!).
* enforce restrictions with your script - i.e. rename file to this and that before using, must be executed from this directory etc.
Any other ideas besides those?
I'm usually working with web so I have little knowledge of making native GUI applications with Python. I'm also seeking recommendation on how I should go about this:
* build my own GUI - this looks nice https://pypi.org/project/PySimpleGUI/
* try out this awesome project https://github.com/chriskiehl/Gooey, although bummer that it only supports `argparse`
I'm
/r/Python
https://redd.it/awu33r
I think this is a common problem for developers who like to create great CLI applications. How do you make it usable by your grandpa? Or by anyone whom the functionality of the script is useful but won't ever pop up a cli and type those commands.
Let's say I have a script that would do a simple task. Something that I could probably run as:
```
$ ./script --file /home/my/file.txt
```
Only ways I could think of how non CLI users can use this are the following:
* make a GUI - everyone knows a GUI and knows how to use a file chooser.
* wrap your python script in an executable (bat file maybe) and provide user prompts for the filename (they'd need to type in really long names though!).
* enforce restrictions with your script - i.e. rename file to this and that before using, must be executed from this directory etc.
Any other ideas besides those?
I'm usually working with web so I have little knowledge of making native GUI applications with Python. I'm also seeking recommendation on how I should go about this:
* build my own GUI - this looks nice https://pypi.org/project/PySimpleGUI/
* try out this awesome project https://github.com/chriskiehl/Gooey, although bummer that it only supports `argparse`
I'm
/r/Python
https://redd.it/awu33r
PyPI
PySimpleGUI
PySimpleGUI is now located on a private PyPI server. Please add to your pip command: --extra-index-url https://PySimpleGUI.net/install
What is the standard(ish) way to make a library configurable?
We have an internal library that we want to make open-source, so we are trying to normalize its structure and workflows. This library has several configuration options that are currently split between hard-coded values and some environment variables, and we want to change it to have all the fields read from an hierarchical path:
* Get it from an environment variables.
* If it's not there - get it from a config file in the project directory.
* If it's not there - get it from a config file in the home directory.
* If it's not there - use the library's defaut.
Is there any standard way to do it? Tools like Flake8 read their configuration [from various files](http://flake8.pycqa.org/en/2.6.0/config.html#per-project), in various formats, but we want to have a single way to configure our project.
/r/Python
https://redd.it/awunwn
We have an internal library that we want to make open-source, so we are trying to normalize its structure and workflows. This library has several configuration options that are currently split between hard-coded values and some environment variables, and we want to change it to have all the fields read from an hierarchical path:
* Get it from an environment variables.
* If it's not there - get it from a config file in the project directory.
* If it's not there - get it from a config file in the home directory.
* If it's not there - use the library's defaut.
Is there any standard way to do it? Tools like Flake8 read their configuration [from various files](http://flake8.pycqa.org/en/2.6.0/config.html#per-project), in various formats, but we want to have a single way to configure our project.
/r/Python
https://redd.it/awunwn
reddit
r/Python - What is the standard(ish) way to make a library configurable?
4 votes and 6 comments so far on Reddit
Django and lists..
Hello!
I have been stuck for a while now with this problem. I would need to create a list of lists for each of my users.User's then could select a some of their lists and input numbers there. I will later use these numbers to show a graph of the selected list.
PS I am pretty new to django so detailed answers would be good. Dont know all the little things yet.. Thanks already!
/r/django
https://redd.it/ax0lfs
Hello!
I have been stuck for a while now with this problem. I would need to create a list of lists for each of my users.User's then could select a some of their lists and input numbers there. I will later use these numbers to show a graph of the selected list.
PS I am pretty new to django so detailed answers would be good. Dont know all the little things yet.. Thanks already!
/r/django
https://redd.it/ax0lfs
reddit
r/django - Django and lists..
0 votes and 0 comments so far on Reddit
Facebook Pixel Conversion Tracking + Flask Template Rendering
So I set my Facebook pixel to track when a page contains for example 'pay' in the URL, but the tracking doesn't seem to be working. I think its because the "pay" route doesn't actually render a template you see, it just redirects the user to an initial page that has its own /intro_page URL (which does render a template, where I could put the pixel code)
I am curious as to what the best approach here is.
I dont wanna double track conversions, so is there any way I can check if it's the first time they've visited?
/r/flask
https://redd.it/ax0ec6
So I set my Facebook pixel to track when a page contains for example 'pay' in the URL, but the tracking doesn't seem to be working. I think its because the "pay" route doesn't actually render a template you see, it just redirects the user to an initial page that has its own /intro_page URL (which does render a template, where I could put the pixel code)
I am curious as to what the best approach here is.
I dont wanna double track conversions, so is there any way I can check if it's the first time they've visited?
/r/flask
https://redd.it/ax0ec6
reddit
r/flask - Facebook Pixel Conversion Tracking + Flask Template Rendering
1 vote and 1 comment so far on Reddit
Handling url_for parameters with flask.
Hey guys. I'm trying to handle some url_for parameters with flask.
I have a page that has a big table of parameters, and then a link that gets made at the end of each row.
For example:
<a href="{ url_for('test', test_type=test_select[4], service_type=test_select[3], test_level='80') }">Test</a>
However, when I take the link, the parameters are in the website URL.
I'm not finding great information online. Do I need to add @app.route options to handle these?
Thanks for the help! :)
EDIT: A little more specifics. Normally I have something like this:
@app.route('/test')
def test:
return(render_template(test.html, parameters and stuff))
I want my test route to also be able to handle a different return if it gets some parameters from a url_for link. I hope that makes sense. I will be around to try to clarify as much as I can!
/r/flask
https://redd.it/awuu1q
Hey guys. I'm trying to handle some url_for parameters with flask.
I have a page that has a big table of parameters, and then a link that gets made at the end of each row.
For example:
<a href="{ url_for('test', test_type=test_select[4], service_type=test_select[3], test_level='80') }">Test</a>
However, when I take the link, the parameters are in the website URL.
I'm not finding great information online. Do I need to add @app.route options to handle these?
Thanks for the help! :)
EDIT: A little more specifics. Normally I have something like this:
@app.route('/test')
def test:
return(render_template(test.html, parameters and stuff))
I want my test route to also be able to handle a different return if it gets some parameters from a url_for link. I hope that makes sense. I will be around to try to clarify as much as I can!
/r/flask
https://redd.it/awuu1q
reddit
r/flask - Handling url_for parameters with flask.
5 votes and 5 comments so far on Reddit
A 4YO's first python program!
Today, I taught my 4 year old cousin to write her first python program. Within a few minutes of explaining to her, she learnt to open the terminal, start python and write code (shown in the image). While explaining to her as to why we need to put parentheses and quotations, I told her that computers are dumb and that they don't understand us unless we follow some rules (syntax). She wrote down "cows have eight legs" to see how the computer responds to it. To her surprise, when the computer printed out the same, she yelled "Computers are really dumb, it says a cow has 8 legs!". It was bedtime by then and she said goodnight and would learn more programming tomorrow.
​
Edit: image
https://i.redd.it/8srpe2iw22k21.png
/r/Python
https://redd.it/ax4gl3
Today, I taught my 4 year old cousin to write her first python program. Within a few minutes of explaining to her, she learnt to open the terminal, start python and write code (shown in the image). While explaining to her as to why we need to put parentheses and quotations, I told her that computers are dumb and that they don't understand us unless we follow some rules (syntax). She wrote down "cows have eight legs" to see how the computer responds to it. To her surprise, when the computer printed out the same, she yelled "Computers are really dumb, it says a cow has 8 legs!". It was bedtime by then and she said goodnight and would learn more programming tomorrow.
​
Edit: image
https://i.redd.it/8srpe2iw22k21.png
/r/Python
https://redd.it/ax4gl3
Free Django Book Released
Hello r/django!
I wanted to share that my beta version of my full stack web development book is now live.
You can check it out on my website: [http://www.codexplore.io/books/crash-course/](http://www.codexplore.io/books/crash-course/)
The Github is here: [https://github.com/codexplore-io/crash-course-django](https://github.com/codexplore-io/crash-course-django)
This is just the "Beta version", so I am open to suggestions if anybody has them. I am using this book as an experiment in "open source publishing", so we shall see how it goes.
I am working on building a programming education website that allows anybody to learn how to program. There are many like it, but I truly believe that people learn much differently, so as many different explanations out there will make it easier for those to learn. Feel free to subscribe to learn more about what we are doing in the next couple of months as we are actively expanding across content mediums. We are going to be putting together a podcast as well, so if you have anyone in mind you would love to hear interviewed in the realm of STEM in general (or specifically Django), PM me or send us a contact on our website at [http://www.codexplore.io/contact](http://www.codexplore.io/contact).
​
Please follow us on Twitter if you find our information useful: [https://twitter.com/codexplore\_io](https://twitter.com/codexplore_io)
​
Any feedback on the book, website or company.
/r/django
https://redd.it/ax3hd5
Hello r/django!
I wanted to share that my beta version of my full stack web development book is now live.
You can check it out on my website: [http://www.codexplore.io/books/crash-course/](http://www.codexplore.io/books/crash-course/)
The Github is here: [https://github.com/codexplore-io/crash-course-django](https://github.com/codexplore-io/crash-course-django)
This is just the "Beta version", so I am open to suggestions if anybody has them. I am using this book as an experiment in "open source publishing", so we shall see how it goes.
I am working on building a programming education website that allows anybody to learn how to program. There are many like it, but I truly believe that people learn much differently, so as many different explanations out there will make it easier for those to learn. Feel free to subscribe to learn more about what we are doing in the next couple of months as we are actively expanding across content mediums. We are going to be putting together a podcast as well, so if you have anyone in mind you would love to hear interviewed in the realm of STEM in general (or specifically Django), PM me or send us a contact on our website at [http://www.codexplore.io/contact](http://www.codexplore.io/contact).
​
Please follow us on Twitter if you find our information useful: [https://twitter.com/codexplore\_io](https://twitter.com/codexplore_io)
​
Any feedback on the book, website or company.
/r/django
https://redd.it/ax3hd5
www.codexplore.io
Super Crash Course in Full Stack Web Development with Python and Django
PEP 584 -- Add + and - operators to the built-in dict class.
https://www.python.org/dev/peps/pep-0584/
/r/Python
https://redd.it/ax4zzb
https://www.python.org/dev/peps/pep-0584/
/r/Python
https://redd.it/ax4zzb
Python Enhancement Proposals (PEPs)
PEP 584 – Add Union Operators To dict | peps.python.org
This PEP proposes adding merge (|) and update (|=) operators to the built-in dict class.
[R] [1903.00374] Model-Based Reinforcement Learning for Atari: Achieving human-level performance on many Atari games after two hours of real-time play
https://arxiv.org/abs/1903.00374
/r/MachineLearning
https://redd.it/ax406x
https://arxiv.org/abs/1903.00374
/r/MachineLearning
https://redd.it/ax406x
arXiv.org
Model-Based Reinforcement Learning for Atari
Model-free reinforcement learning (RL) can be used to learn effective policies for complex tasks, such as Atari games, even from image observations. However, this typically requires very large...
I wanted to test whether a certain signal was fired or not so I wrote this mixin that you can add to a Django TestCase. Includes a test file that demonstrates usage.
https://gist.github.com/JordanReiter/14a800ae524ac8928b8d55b8b78a40e9
/r/django
https://redd.it/axbrbx
https://gist.github.com/JordanReiter/14a800ae524ac8928b8d55b8b78a40e9
/r/django
https://redd.it/axbrbx
Gist
Simple TestCase Mixin for testing whether signals are fired, and testing for specific signal values
Simple TestCase Mixin for testing whether signals are fired, and testing for specific signal values - signal_testcase.py
The State of Sparsity in Neural Networks
https://arxiv.org/abs/1902.09574
/r/MachineLearning
https://redd.it/axany4
https://arxiv.org/abs/1902.09574
/r/MachineLearning
https://redd.it/axany4
arXiv.org
The State of Sparsity in Deep Neural Networks
We rigorously evaluate three state-of-the-art techniques for inducing sparsity in deep neural networks on two large-scale learning tasks: Transformer trained on WMT 2014 English-to-German, and...
OTP/Two factor authentication on Django?
I'm trying to add two factor authentication to my project, but the libriaries i found for Django have very little docs and i don't understand how to implement it into my own project. Is there an example, a tutorial or a widely used library i can follow to make my own implementation?
/r/django
https://redd.it/axd9nc
I'm trying to add two factor authentication to my project, but the libriaries i found for Django have very little docs and i don't understand how to implement it into my own project. Is there an example, a tutorial or a widely used library i can follow to make my own implementation?
/r/django
https://redd.it/axd9nc
reddit
r/django - OTP/Two factor authentication on Django?
1 vote and 0 comments so far on Reddit
Update datapoint in Postgress
Hi! I'm new to flask and Postgres. I want to update a column based on user input. Should I create a separate get and post methods or use my existing ones?
​
I want to update the count of an existing entry.
​
@app.route('/')
def get_exams():
# fetching from the database
session = Session()
exam_objects = session.query(Exam).all()
# transforming into JSON-serializable objects
schema = ExamSchema(many=True)
exams = schema.dump(exam_objects)
# serializing as JSON
session.close()
return jsonify(exams.data)
@app.route('/', methods=['POST'])
def add_exam():
# mount exam object
posted_exam = ExamSchema(only=('title', 'description', 'count'))\
.load(request.get_json())
exam = Exam(**posted_exam.data, created_by="HTTP post request")
# persist exam
session = Session()
session.add(exam)
session.commit()
# return created exam
new_exam = ExamSchema().dump(exam).data
session.close()
return jsonify(new_exam), 201
​
/r/flask
https://redd.it/axgl8j
Hi! I'm new to flask and Postgres. I want to update a column based on user input. Should I create a separate get and post methods or use my existing ones?
​
I want to update the count of an existing entry.
​
@app.route('/')
def get_exams():
# fetching from the database
session = Session()
exam_objects = session.query(Exam).all()
# transforming into JSON-serializable objects
schema = ExamSchema(many=True)
exams = schema.dump(exam_objects)
# serializing as JSON
session.close()
return jsonify(exams.data)
@app.route('/', methods=['POST'])
def add_exam():
# mount exam object
posted_exam = ExamSchema(only=('title', 'description', 'count'))\
.load(request.get_json())
exam = Exam(**posted_exam.data, created_by="HTTP post request")
# persist exam
session = Session()
session.add(exam)
session.commit()
# return created exam
new_exam = ExamSchema().dump(exam).data
session.close()
return jsonify(new_exam), 201
​
/r/flask
https://redd.it/axgl8j
reddit
r/flask - Update datapoint in Postgress
0 votes and 0 comments so far on Reddit