I feel like I'm understanding limit_choices_to wrong
Hello. I've read the documentation page on it and searched Google/SO for answers but I just can't seem to wrap my head around it.
I've got the following schema:
class MainModel(models.Model):
pass
class Criteria(models.Model):
parent = models.ForeignKey(MainModel, on_delete=models.CASCADE)
class ChildModel(models.Model):
parent = models.ForeignKey(MainModel, on_delete=models.CASCADE)
What I want to do is have a many-to-many relationship between ChildModel and Criteria, and limit the options of the Criteria to the MainModel's criteria set.
So basically the following:
class ChildModel(models.Model):
parent = models.ForeignKey(MainModel, on_delete=models.CASCADE)
criterias = models.ManyToManyField('Criteria', limit_choices_to=parent.criteria_set.all())
// I want to do this ^^^ (criterias isnt the plural form but bear with me)
But I keep getting errors about the parent not having an attribute "criteria_set" (which I assume would be the way to get the parent's list of criteria)
Am I going about this the wrong way? How would I make it work?
If something's unclear in my question please
/r/djangolearning
https://redd.it/bakda6
Hello. I've read the documentation page on it and searched Google/SO for answers but I just can't seem to wrap my head around it.
I've got the following schema:
class MainModel(models.Model):
pass
class Criteria(models.Model):
parent = models.ForeignKey(MainModel, on_delete=models.CASCADE)
class ChildModel(models.Model):
parent = models.ForeignKey(MainModel, on_delete=models.CASCADE)
What I want to do is have a many-to-many relationship between ChildModel and Criteria, and limit the options of the Criteria to the MainModel's criteria set.
So basically the following:
class ChildModel(models.Model):
parent = models.ForeignKey(MainModel, on_delete=models.CASCADE)
criterias = models.ManyToManyField('Criteria', limit_choices_to=parent.criteria_set.all())
// I want to do this ^^^ (criterias isnt the plural form but bear with me)
But I keep getting errors about the parent not having an attribute "criteria_set" (which I assume would be the way to get the parent's list of criteria)
Am I going about this the wrong way? How would I make it work?
If something's unclear in my question please
/r/djangolearning
https://redd.it/bakda6
reddit
r/djangolearning - I feel like I'm understanding limit_choices_to wrong
1 vote and 0 comments so far on Reddit
Hitting back button on Django form wizard causes page expired error(and nukes all data), particularly on Internet Explorer?
Hey all, creating multi-step forms using django form-wizard and on firefox and chrome it seems to work fine hitting the back and forwards buttons(both using provided buttons and with browser). But using IE, when hitting the browser back button, it said 'Page Expired' and all the data previously entered in the forms was lost.
Any idea how to prevent this or what is going wrong? Thanks guys.
/r/django
https://redd.it/bar7tx
Hey all, creating multi-step forms using django form-wizard and on firefox and chrome it seems to work fine hitting the back and forwards buttons(both using provided buttons and with browser). But using IE, when hitting the browser back button, it said 'Page Expired' and all the data previously entered in the forms was lost.
Any idea how to prevent this or what is going wrong? Thanks guys.
/r/django
https://redd.it/bar7tx
reddit
r/django - Hitting back button on Django form wizard causes page expired error(and nukes all data), particularly on Internet Explorer?
0 votes and 0 comments so far on Reddit
Customizing the user registration flow using django rest-auth for social authentication
I am stuck with a situation and can't seem to find a good solution on how to proceed further. Currently, I am able to authenticate a user using google. So the person is able to create an account and logs in. However, in doing so, the user already has a randomly generated username and all. I want to create a situation where when a user is authenticated via google, they are redirected to a registration form where they can provide a username of their own choice. What is the most efficient way of going about this? My main goal is to ensure that the blacklisted usernames which we can provide in the allauth settings is also utilized when a user provides their own username.
/r/django
https://redd.it/baknw3
I am stuck with a situation and can't seem to find a good solution on how to proceed further. Currently, I am able to authenticate a user using google. So the person is able to create an account and logs in. However, in doing so, the user already has a randomly generated username and all. I want to create a situation where when a user is authenticated via google, they are redirected to a registration form where they can provide a username of their own choice. What is the most efficient way of going about this? My main goal is to ensure that the blacklisted usernames which we can provide in the allauth settings is also utilized when a user provides their own username.
/r/django
https://redd.it/baknw3
reddit
r/django - Customizing the user registration flow using django rest-auth for social authentication
0 votes and 0 comments so far on Reddit
Etch-A-Snap, a Python powered Etch-A-Sketch camera
https://www.twobitarcade.net/article/etch-a-snap/
/r/Python
https://redd.it/bark86
https://www.twobitarcade.net/article/etch-a-snap/
/r/Python
https://redd.it/bark86
Two Bit Arcade
Etch-A-Snap | The Raspberry Pi powered Etch-A-Sketch camera
Etch-A-Snap is (probably) the worlds first Etch-A-Sketch Camera. Powered by a Raspberry Pi Zero (or Zero W) it snaps photos just like any other camera, but outputs them by drawing to an Pocket Etch-A-Sketch screen. Quite slowly. Photos are processed down…
“NameError: global name” Question
Im new to python and flask, however I am not new to programming languages by any means.
I am building a simple web app and something caught my attention that I found kinda strange. (From my point of view)
I added url_for in an html template and it works, however I forgot to import it into my .py script and got an error(as I should)
From my understanding Jinja2 is responsible for the HTML part. Is it safe to say that Jinja2 has all modules imported as part of it base and always readily accessible, therefore never needing “import”?
/r/flask
https://redd.it/baczau
Im new to python and flask, however I am not new to programming languages by any means.
I am building a simple web app and something caught my attention that I found kinda strange. (From my point of view)
I added url_for in an html template and it works, however I forgot to import it into my .py script and got an error(as I should)
From my understanding Jinja2 is responsible for the HTML part. Is it safe to say that Jinja2 has all modules imported as part of it base and always readily accessible, therefore never needing “import”?
/r/flask
https://redd.it/baczau
reddit
r/flask - “NameError: global name” Question
4 votes and 4 comments so far on Reddit
Need help with AJAX calls, and redirect
Hey everyone,
This is my first time using flask and I am looking for some help. The goal of the application is to display most frequent words in lyrics. I have written a class that cleans the data, and pushes dictionary into json file. I currently have the main page (base.html) which accepts artist name, song name, and onclick it generates data into json file. I use chartJS which generates a pie chart for me on a chart.html page, using the data from the json file. I am forced to render\_template to see the chart. My question is, how can I make an ajax request so that on click I can generate the graph in my base.html page after the click?
​
Thank you.
/r/flask
https://redd.it/baat9b
Hey everyone,
This is my first time using flask and I am looking for some help. The goal of the application is to display most frequent words in lyrics. I have written a class that cleans the data, and pushes dictionary into json file. I currently have the main page (base.html) which accepts artist name, song name, and onclick it generates data into json file. I use chartJS which generates a pie chart for me on a chart.html page, using the data from the json file. I am forced to render\_template to see the chart. My question is, how can I make an ajax request so that on click I can generate the graph in my base.html page after the click?
​
Thank you.
/r/flask
https://redd.it/baat9b
reddit
r/flask - Need help with AJAX calls, and redirect
4 votes and 8 comments so far on Reddit
Running Django in Production (Talk Python To Me)
https://talkpython.fm/episodes/show/206/running-django-in-production
/r/django
https://redd.it/batw10
https://talkpython.fm/episodes/show/206/running-django-in-production
/r/django
https://redd.it/batw10
talkpython.fm
Running Django in Production
Let's talk about running Django in production. On this episode, you'll meet Michael Herman who used to work on realpython.com and today is running testdriven.io. We also cover some of the tradeoffs of a set of microservices and a monolith and a round trip…
Need help with Flask API regarding security and JWT
Hello fellows,
​
Long story short, I am developing my API using Flask and I want to secure it against replay attacks and other MITM things, as well as random people querying the address.
​
So I have seen that JWT could be the answer (using secure HTTP of course to prevent those nice MITM) but there is something I definitely can't understand.
​
Once we auth ourself, the server gives us a token, that we are supposed to **store** and send at every request to prove the server we are the real auth person.
But by doing so, considering we send the token using HTTPs so saying like 'okay it's supposed to be enough secure (https) and anyway we won't be querying the api in vulnerable environnement such as public wifi etc..' and considering the token will be linked to a socket right ? Like we link the TOKEN to A USER, for A SESSION therefor the TOKEN is only good for our actual socket (IP/PORT couple), correct me if i'm wrong.
​
So this ensure only *US* at this exact moment can use this token, and not some guy from idk where since that, even if he gets it, he will not have the
/r/flask
https://redd.it/ba7bg1
Hello fellows,
​
Long story short, I am developing my API using Flask and I want to secure it against replay attacks and other MITM things, as well as random people querying the address.
​
So I have seen that JWT could be the answer (using secure HTTP of course to prevent those nice MITM) but there is something I definitely can't understand.
​
Once we auth ourself, the server gives us a token, that we are supposed to **store** and send at every request to prove the server we are the real auth person.
But by doing so, considering we send the token using HTTPs so saying like 'okay it's supposed to be enough secure (https) and anyway we won't be querying the api in vulnerable environnement such as public wifi etc..' and considering the token will be linked to a socket right ? Like we link the TOKEN to A USER, for A SESSION therefor the TOKEN is only good for our actual socket (IP/PORT couple), correct me if i'm wrong.
​
So this ensure only *US* at this exact moment can use this token, and not some guy from idk where since that, even if he gets it, he will not have the
/r/flask
https://redd.it/ba7bg1
reddit
r/flask - Need help with Flask API regarding security and JWT
5 votes and 8 comments so far on Reddit
Python programmers of reddit: what's the most useful tiny little efficiency you've discovered that's improved your programming hugely?
Whether it's default dicts, enumerate, a way to combine functions really efficiently, or whatever, what's the best tiny trick you've discovered that's improved your code massively?
/r/Python
https://redd.it/basnhi
Whether it's default dicts, enumerate, a way to combine functions really efficiently, or whatever, what's the best tiny trick you've discovered that's improved your code massively?
/r/Python
https://redd.it/basnhi
reddit
r/Python - Python programmers of reddit: what's the most useful tiny little efficiency you've discovered that's improved your programming…
597 votes and 452 comments so far on Reddit
Python REST APIs With Flask, Connexion, and SQLAlchemy – Part 3
https://realpython.com/flask-connexion-rest-api-part-3/
/r/Python
https://redd.it/baufsm
https://realpython.com/flask-connexion-rest-api-part-3/
/r/Python
https://redd.it/baufsm
Realpython
Python REST APIs With Flask, Connexion, and SQLAlchemy – Part 3 – Real Python
In this three-part tutorial series, you'll create a RESTful API from scratch to keep track of people and notes using the Flask web framework. You'll also test your API with Swagger UI API documentation. In part three, you'll use SQLAlchemy to provide the…
Is what I'm trying to do even possible?
This might sound really stupid but how can I do something like this:
i = 'profile'
return self.user.i
Where the variable "i" is the attribute.
/r/django
https://redd.it/bb246d
This might sound really stupid but how can I do something like this:
i = 'profile'
return self.user.i
Where the variable "i" is the attribute.
/r/django
https://redd.it/bb246d
reddit
r/django - Is what I'm trying to do even possible?
0 votes and 2 comments so far on Reddit
Reports (i.e. Crystal) via Python
Does anybody know of any reporting tools that have been developed in Python?
Specifically, what I'm looking for is either a) a way to generate PDFs from a crystal .RPT file or b) an "open" format that could generate something similar fairly "easily" for an end user. I guess I envision something like like a flask or django template, but could then generate a report in PDF format when ran...
We use crystal reports pretty extensively in my organization for both multipage reports (for instance, sales reports) and for reports that are generally single pages (for instance, invoices are usually single page unless there are more than ~10 line items).
I've considered writing a django app (it's what I'm familiar with) to accomplish something like this for myself, but would want to make it so others could also potentially develop their own reports... I've built PDF reports using straight python before, and while that works for me, I can't imagine asking others to write python code to customize their own reports-- and I really want to avoid reinventing the wheel if a product already exists (preferably open-source so it can be incorporated into another open-source project, but if necessary,
/r/Python
https://redd.it/bb3kqk
Does anybody know of any reporting tools that have been developed in Python?
Specifically, what I'm looking for is either a) a way to generate PDFs from a crystal .RPT file or b) an "open" format that could generate something similar fairly "easily" for an end user. I guess I envision something like like a flask or django template, but could then generate a report in PDF format when ran...
We use crystal reports pretty extensively in my organization for both multipage reports (for instance, sales reports) and for reports that are generally single pages (for instance, invoices are usually single page unless there are more than ~10 line items).
I've considered writing a django app (it's what I'm familiar with) to accomplish something like this for myself, but would want to make it so others could also potentially develop their own reports... I've built PDF reports using straight python before, and while that works for me, I can't imagine asking others to write python code to customize their own reports-- and I really want to avoid reinventing the wheel if a product already exists (preferably open-source so it can be incorporated into another open-source project, but if necessary,
/r/Python
https://redd.it/bb3kqk
reddit
r/Python - Reports (i.e. Crystal) via Python
0 votes and 0 comments so far on Reddit
How to stop caching? Its driving me nuts!
Im using the dev server that comes with Flask. Every time I update CSS or a template, I cant even hard refresh to get the new stuff to show. I have to restart the server. I used this before and it worked months ago, but for some reason its not working with the new web app I am working on.
​
@app.after\_request
def after\_request(response):
response.headers\["Cache-Control"\] = "no-cache, no-store, must-revalidate, public, max-age=0"
response.headers\["Expires"\] = '0'
response.headers\["Pragma"\] = "no-cache"
return response
/r/flask
https://redd.it/ba2zul
Im using the dev server that comes with Flask. Every time I update CSS or a template, I cant even hard refresh to get the new stuff to show. I have to restart the server. I used this before and it worked months ago, but for some reason its not working with the new web app I am working on.
​
@app.after\_request
def after\_request(response):
response.headers\["Cache-Control"\] = "no-cache, no-store, must-revalidate, public, max-age=0"
response.headers\["Expires"\] = '0'
response.headers\["Pragma"\] = "no-cache"
return response
/r/flask
https://redd.it/ba2zul
reddit
r/flask - How to stop caching? Its driving me nuts!
7 votes and 10 comments so far on Reddit
[AF] Using WTForms to pass a variable to tweepy python script
Hi,
I've been following the flask tutorial from Miguel Grinberg. currently up to stage 3 following wtforms.
I'm trying to take an input of a user name for a twitter account and then input that into a python script with tweepy and return something like the number of tweets or from said account and display that to an output page.
Everything is working so far and I take a username but how do I then call input that into a second script? and also how do I return this data to output page. I have a separate script that returns the tweepy data into a json file.
The site is up and running with uwsgi and nginx all working correctly so far which is good. Any help would be amazing as I'm pretty new to this and want to experiment but i'm having some difficultly wrapped my head around some concepts when it comes to processing the data and not running everything from a single .py file
ideally I would like something like this page
https://tweetanalyzer.net/
/r/flask
https://redd.it/ba6vb6
Hi,
I've been following the flask tutorial from Miguel Grinberg. currently up to stage 3 following wtforms.
I'm trying to take an input of a user name for a twitter account and then input that into a python script with tweepy and return something like the number of tweets or from said account and display that to an output page.
Everything is working so far and I take a username but how do I then call input that into a second script? and also how do I return this data to output page. I have a separate script that returns the tweepy data into a json file.
The site is up and running with uwsgi and nginx all working correctly so far which is good. Any help would be amazing as I'm pretty new to this and want to experiment but i'm having some difficultly wrapped my head around some concepts when it comes to processing the data and not running everything from a single .py file
ideally I would like something like this page
https://tweetanalyzer.net/
/r/flask
https://redd.it/ba6vb6
Introducing pybrowser !
Hello everybody,
**pybrowser** is an attempt to simplify browser automation designed keeping end user in mind. Here is an example of usage,
from pybrowser import Browser
with Browser(browser_name=Browser.CHROME) as b:
b.goto("https://www.google.com/")
b.input("name:=q").enter("news")
b.button("name:=btnK").click()
b.take_screenshot()
print(b.html().elements.links())
It's a simple API inspired by ruby's watir with selenium and requests under the hood.
This is the first version for public usage (v0.0.1) and hence expect it to be buggy and what not. At this point definitely don't recommend for commercial use. But do play around and have fun !
[Read more...](https://pybrowser.readthedocs.io/en/latest/)
This is also my first API. So welcome any feedback :)
/r/Python
https://redd.it/bb4bdx
Hello everybody,
**pybrowser** is an attempt to simplify browser automation designed keeping end user in mind. Here is an example of usage,
from pybrowser import Browser
with Browser(browser_name=Browser.CHROME) as b:
b.goto("https://www.google.com/")
b.input("name:=q").enter("news")
b.button("name:=btnK").click()
b.take_screenshot()
print(b.html().elements.links())
It's a simple API inspired by ruby's watir with selenium and requests under the hood.
This is the first version for public usage (v0.0.1) and hence expect it to be buggy and what not. At this point definitely don't recommend for commercial use. But do play around and have fun !
[Read more...](https://pybrowser.readthedocs.io/en/latest/)
This is also my first API. So welcome any feedback :)
/r/Python
https://redd.it/bb4bdx
reddit
r/Python - Introducing pybrowser !
77 votes and 5 comments so far on Reddit
Tutorial: 3D Programming with Python for Physics Simulations
https://www.youtube.com/watch?v=KI0tjZUkb5A
/r/Python
https://redd.it/bb5sac
https://www.youtube.com/watch?v=KI0tjZUkb5A
/r/Python
https://redd.it/bb5sac
YouTube
[2.8] Tutorial: 3D Programming with Python and Blender for Physics Simulations
In this tutorial I will teach you how to create physics simulations using Blender 2.8 and Python.
The Ultimate Addon Development Course, Make Complex Addons for Blender!
https://gum.co/fciiU
Cool Add-ons for Blender:
Human Generator:
https://bit.ly/3rBjJXy…
The Ultimate Addon Development Course, Make Complex Addons for Blender!
https://gum.co/fciiU
Cool Add-ons for Blender:
Human Generator:
https://bit.ly/3rBjJXy…
Nimoy testing framework - 0.0.1b7
After a long break I've Just released beta 7 of the [Nimoy testing framework](https://github.com/browncoat-ninjas/nimoy)!
This version introduces syntactic sugar for [staging mock responses](https://github.com/browncoat-ninjas/nimoy#pretty-mock-response-staging):
```
class MySpec(Specification):
def my_feature_method(self):
with setup:
the_mock = mock.Mock()
with when:
the_mock.some_method() << [5, 6, 7]
with then:
the_mock.some_method() == 5
the_mock.some_method() == 6
the_mock.some_method() == 7
```
/r/Python
https://redd.it/bb74dc
After a long break I've Just released beta 7 of the [Nimoy testing framework](https://github.com/browncoat-ninjas/nimoy)!
This version introduces syntactic sugar for [staging mock responses](https://github.com/browncoat-ninjas/nimoy#pretty-mock-response-staging):
```
class MySpec(Specification):
def my_feature_method(self):
with setup:
the_mock = mock.Mock()
with when:
the_mock.some_method() << [5, 6, 7]
with then:
the_mock.some_method() == 5
the_mock.some_method() == 6
the_mock.some_method() == 7
```
/r/Python
https://redd.it/bb74dc
GitHub
GitHub - browncoat-ninjas/nimoy: A testing and specification framework for Python 3
A testing and specification framework for Python 3 - GitHub - browncoat-ninjas/nimoy: A testing and specification framework for Python 3
Developing a Real-Time Taxi App with Django Channels and Angular - updated!
https://testdriven.io/courses/real-time-app-with-django-channels-and-angular/
/r/django
https://redd.it/bb7wqv
https://testdriven.io/courses/real-time-app-with-django-channels-and-angular/
/r/django
https://redd.it/bb7wqv
reddit
r/django - Developing a Real-Time Taxi App with Django Channels and Angular - updated!
0 votes and 1 comment so far on Reddit
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/bb8dv4
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/bb8dv4
reddit
r/Python - What's everyone working on this week?
0 votes and 2 comments so far on Reddit