Hey /r/Python! I made a weird game about simulating evolution of intelligence in PyGame. Tell me what you think!
https://www.youtube.com/watch?v=2boI6R0Gx8A
/r/Python
https://redd.it/6vdaiv
https://www.youtube.com/watch?v=2boI6R0Gx8A
/r/Python
https://redd.it/6vdaiv
YouTube
Critter Evolution - A game for bored nerds
Subscribe for more robotics/software projects!
I made an evolutionary game where the brains of critters get smarter over time. The critters live, mate, eat, hunt, scavenge, sleep, and die. When they mate, their decision-making process is put into the child…
I made an evolutionary game where the brains of critters get smarter over time. The critters live, mate, eat, hunt, scavenge, sleep, and die. When they mate, their decision-making process is put into the child…
Django and concurrent database access
I'm fairly new to developing with Django. As it happens I am using Celery for asynchronous task handling, but I think this question could pertain to Django even without Celery.
In the situation where Apache or Gunicorn is configured to handle multiple requests simultaneously, one can conceivably have the situation where one request is reading from the database to generate a view while another is either writing or even deleting content.
Now at least the way my code is written, the read request may need to query multiple models - often doing a filter on a second model based on some logic using values read from the first model. At a minimum such a relationship may even simply be a foreign key constraint in the database.
So I believe multiple database accesses may happen while generating the view for the user who is making the query.
Right now I presume that my code will crash should another process (be it a Django instance or perhaps a Celery async task) be modifying or deleting entries from the database (for example another user is logged in and has requested some entries to be deleted).
What is a good way to deal with this?
/r/django
https://redd.it/6ve3wp
I'm fairly new to developing with Django. As it happens I am using Celery for asynchronous task handling, but I think this question could pertain to Django even without Celery.
In the situation where Apache or Gunicorn is configured to handle multiple requests simultaneously, one can conceivably have the situation where one request is reading from the database to generate a view while another is either writing or even deleting content.
Now at least the way my code is written, the read request may need to query multiple models - often doing a filter on a second model based on some logic using values read from the first model. At a minimum such a relationship may even simply be a foreign key constraint in the database.
So I believe multiple database accesses may happen while generating the view for the user who is making the query.
Right now I presume that my code will crash should another process (be it a Django instance or perhaps a Celery async task) be modifying or deleting entries from the database (for example another user is logged in and has requested some entries to be deleted).
What is a good way to deal with this?
/r/django
https://redd.it/6ve3wp
reddit
Django and concurrent database access • r/django
I'm fairly new to developing with Django. As it happens I am using Celery for asynchronous task handling, but I think this question could pertain...
The Needle in the Haystack: Wrangling Celery Workflows
https://engineering.rover.com/blog/ops/2017/08/21/wrangling-celery-workflows/
/r/django
https://redd.it/6vbz1s
https://engineering.rover.com/blog/ops/2017/08/21/wrangling-celery-workflows/
/r/django
https://redd.it/6vbz1s
Rover.com
One-Column Layout | Rover.com
Find 5 star dog sitters on Rover.com. Book dog sitting or dog boarding online! 24/7 customer support, peace of mind protection. Better than a dog kennel.
The simple way to understand Django models
https://arevej.me/django-models/
/r/djangolearning
https://redd.it/6vblnc
https://arevej.me/django-models/
/r/djangolearning
https://redd.it/6vblnc
reddit
The simple way to understand Django models • r/djangolearning
7 points and 3 comments so far on reddit
How do you format text that was taken from a model field?
I'm not even sure how to ask this question so I apologize if this is an easy Google. I am at least pretty sure it's Django-related.
This is a basic blog. Here is the relevant model structure:
class Post(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField(max_length=100)
body = models.TextField()
posted_date = models.DateField(auto_now_add=True)
category = models.ManyToManyField('Category')
Each instance of the above model I am calling "p." So now in my template, I am printing the title and body of the post:
...
<h3>{{ p.title|safe }}</h3>
<h6>Posted on {{ p.posted_date }}</h6>
<p>{{ p.body|safe }}</p>
...
This is all working just fine. My problem is, when I actually load all of this in my browser, no matter what styling I do to
<p>{{ p.body|safe }}</p>
it does not take. Boostrap classes don't work. Custom CSS doesn't work. In-line CSS doesn't work. Am I missing something?
/r/django
https://redd.it/6vffny
I'm not even sure how to ask this question so I apologize if this is an easy Google. I am at least pretty sure it's Django-related.
This is a basic blog. Here is the relevant model structure:
class Post(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField(max_length=100)
body = models.TextField()
posted_date = models.DateField(auto_now_add=True)
category = models.ManyToManyField('Category')
Each instance of the above model I am calling "p." So now in my template, I am printing the title and body of the post:
...
<h3>{{ p.title|safe }}</h3>
<h6>Posted on {{ p.posted_date }}</h6>
<p>{{ p.body|safe }}</p>
...
This is all working just fine. My problem is, when I actually load all of this in my browser, no matter what styling I do to
<p>{{ p.body|safe }}</p>
it does not take. Boostrap classes don't work. Custom CSS doesn't work. In-line CSS doesn't work. Am I missing something?
/r/django
https://redd.it/6vffny
reddit
How do you format text that was taken from a model field? • r/django
I'm not even sure how to ask this question so I apologize if this is an easy Google. I am at least pretty sure it's Django-related. This...
UserProfile: Should be another app or just a model?
I thinking of doing a Pinterest clone and maybe that others clone projects like Reddit, Instagram or Hacker News. And I wondering if is better have the user profile like an app or just a model in the general view.
Also, what kind of things I can put on it? bio, avatar, or something like that?
/r/django
https://redd.it/6vj9yr
I thinking of doing a Pinterest clone and maybe that others clone projects like Reddit, Instagram or Hacker News. And I wondering if is better have the user profile like an app or just a model in the general view.
Also, what kind of things I can put on it? bio, avatar, or something like that?
/r/django
https://redd.it/6vj9yr
reddit
UserProfile: Should be another app or just a model? • r/django
I thinking of doing a Pinterest clone and maybe that others clone projects like Reddit, Instagram or Hacker News. And I wondering if is better...
[Opening] Flask Dev Wanted for Open Source Project
I am looking for an experienced Flask developer to create a poc web app. The developed app will be open sourced for further development. Compensation offered in Bitcoin or Monero. PM for more details. Thx.
/r/flask
https://redd.it/6vlmpx
I am looking for an experienced Flask developer to create a poc web app. The developed app will be open sourced for further development. Compensation offered in Bitcoin or Monero. PM for more details. Thx.
/r/flask
https://redd.it/6vlmpx
reddit
[Opening] Flask Dev Wanted for Open Source Project • r/flask
I am looking for an experienced Flask developer to create a poc web app. The developed app will be open sourced for further development....
A large list of interesting open source projects in Python. Only active and interesting projects!
https://github.com/lk-geimfari/awesomo/blob/master/languages/PYTHON.md
/r/Python
https://redd.it/6vilsp
https://github.com/lk-geimfari/awesomo/blob/master/languages/PYTHON.md
/r/Python
https://redd.it/6vilsp
GitHub
awesomo/languages/PYTHON.md at main · lk-geimfari/awesomo
Cool open source projects. Choose your project and get involved in Open Source development now. - lk-geimfari/awesomo
[R] High Quality 3D Object Reconstruction from a Single Color Image
http://bair.berkeley.edu/blog/2017/08/23/high-quality-3d-obj-reconstruction/
/r/MachineLearning
https://redd.it/6vjzte
http://bair.berkeley.edu/blog/2017/08/23/high-quality-3d-obj-reconstruction/
/r/MachineLearning
https://redd.it/6vjzte
The Berkeley Artificial Intelligence Research Blog
High Quality 3D Object Reconstruction from a Single Color Image
The BAIR Blog
[AF]Need assistance building joined SQLAlchemy queries. Willing to compensate.
Long story short I'm building an application for a client and I have 4 tables (Customer, Materials, Hours, Attachments) backref'd to a Workorder table, and all linked in a link_table.
It's fully functional and working fine, however I need to build a filter / query system so my client can run reports such as X employee's hours between Y dates, or X employee's hours between Y dates where customer = Z.
Most queries I've run into with SQLAlchemy I've been able to build just fine, even filters using kwargs, however I don't have the time to figure out joining tables, querying backrefs etc. as I've got other modules to focus on for this project, and I need to present it by Friday.
If someone would be willing to help I can throw a few bucks your way. My code is clean and if you've done this before it shouldn't take you very long at all.
Thanks!
/r/flask
https://redd.it/6vkmto
Long story short I'm building an application for a client and I have 4 tables (Customer, Materials, Hours, Attachments) backref'd to a Workorder table, and all linked in a link_table.
It's fully functional and working fine, however I need to build a filter / query system so my client can run reports such as X employee's hours between Y dates, or X employee's hours between Y dates where customer = Z.
Most queries I've run into with SQLAlchemy I've been able to build just fine, even filters using kwargs, however I don't have the time to figure out joining tables, querying backrefs etc. as I've got other modules to focus on for this project, and I need to present it by Friday.
If someone would be willing to help I can throw a few bucks your way. My code is clean and if you've done this before it shouldn't take you very long at all.
Thanks!
/r/flask
https://redd.it/6vkmto
reddit
[AF]Need assistance building joined SQLAlchemy queries.... • r/flask
Long story short I'm building an application for a client and I have 4 tables (Customer, Materials, Hours, Attachments) backref'd to a Workorder...
I made a real-time python IDE. Anyone have any feedback?
https://github.com/Almenon/AREPL
see it in action below!
https://puu.sh/x1a1U/1fdfd3899c.gif
/r/Python
https://redd.it/6vodl4
https://github.com/Almenon/AREPL
see it in action below!
https://puu.sh/x1a1U/1fdfd3899c.gif
/r/Python
https://redd.it/6vodl4
GitHub
Almenon/AREPL
AREPL - python scratchpad with real-time code evaluation
How can I get data fro QuerySet dict received via AJAX to Django View to create model objects ?
I have a model and want to create record based on the data recieved to my view from a AJAX call:
In models.py
--------------------------------------
class Items(models.Model):
item = models.CharField (max_length=128, blank=False,null=False)
qty = models.CharField (max_length=128, blank=False,null=False)
price = models.CharField (max_length=128, blank=False,null=False)
In views.py
--------------------------------------
if request.is_ajax():
if request.method == 'GET':
json_data = request.GET
print("LET'S DUMP THE DATA NOW!!")
data = json.dumps(json_data)
print(data)
Output to console:
I am recieving a dictionary from ajax to my view like this:
--------------------------------------
{"deals[0][Price]": "400", "deals[1][Item]": "Diet Donut", "deals[2][Price]": "180", "deals[1][Price]": "100", "deals[0][Item]": "Donut 4", "deals[2][Item]": "HazelNut Donut", "deals[1][Quantity]": "1", "deals[0][Quantity]": "4", "deals[2][Quantity]": "10"}
HTML-JS part
--------------------------------------
Page1.html
<script>
var items = [];
var qtys = [];
$(document).ready(function() {
var deal_collection = {
deals:[]
};
var jsonData = {};
// Getting data on a CLICK here for the variables
$('a[id^="tag"]').click(function() {
var index=$(this).index()-1;
var text = $(this).text();
var inv = {{ inv_all|safe }};
var item = inv[index].fields.item_name;
var qty = inv[index].fields.quantity;
var price = inv[index].fields.price;
// Adding to array
deal_collection.deals.push({
"Item":item,
"Quantity":qty,
"Price":price
});
});
});
//Saving deal_collection to localStorage so that it can be retireved on the Next page
$('#ajax_call').click(function(){
alert("AJAX Call Clicked");
console.log("AJAX Call clicked");
if (typeof(Storage) !== "undefined") {
localStorage.setItem('deal_array',JSON.stringify(deal_collection))
console.log("Data stored to storage")
} else {
// Sorry! No Web Storage support..
alert('No Storage available')
}
});
</script>
Page2.html:
<script>
var arr = JSON.parse(localStorage.getItem("deal_array"));
$.each(arr, function(i) {
console.log(arr[i]);
});
var msg = "Success !!!"
$.ajax({
url: '{% url 'ajax' %}',
type: 'GET',
data: arr,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
alert(msg);
}
});
});
</script>
/r/django
https://redd.it/6vp3hu
I have a model and want to create record based on the data recieved to my view from a AJAX call:
In models.py
--------------------------------------
class Items(models.Model):
item = models.CharField (max_length=128, blank=False,null=False)
qty = models.CharField (max_length=128, blank=False,null=False)
price = models.CharField (max_length=128, blank=False,null=False)
In views.py
--------------------------------------
if request.is_ajax():
if request.method == 'GET':
json_data = request.GET
print("LET'S DUMP THE DATA NOW!!")
data = json.dumps(json_data)
print(data)
Output to console:
I am recieving a dictionary from ajax to my view like this:
--------------------------------------
{"deals[0][Price]": "400", "deals[1][Item]": "Diet Donut", "deals[2][Price]": "180", "deals[1][Price]": "100", "deals[0][Item]": "Donut 4", "deals[2][Item]": "HazelNut Donut", "deals[1][Quantity]": "1", "deals[0][Quantity]": "4", "deals[2][Quantity]": "10"}
HTML-JS part
--------------------------------------
Page1.html
<script>
var items = [];
var qtys = [];
$(document).ready(function() {
var deal_collection = {
deals:[]
};
var jsonData = {};
// Getting data on a CLICK here for the variables
$('a[id^="tag"]').click(function() {
var index=$(this).index()-1;
var text = $(this).text();
var inv = {{ inv_all|safe }};
var item = inv[index].fields.item_name;
var qty = inv[index].fields.quantity;
var price = inv[index].fields.price;
// Adding to array
deal_collection.deals.push({
"Item":item,
"Quantity":qty,
"Price":price
});
});
});
//Saving deal_collection to localStorage so that it can be retireved on the Next page
$('#ajax_call').click(function(){
alert("AJAX Call Clicked");
console.log("AJAX Call clicked");
if (typeof(Storage) !== "undefined") {
localStorage.setItem('deal_array',JSON.stringify(deal_collection))
console.log("Data stored to storage")
} else {
// Sorry! No Web Storage support..
alert('No Storage available')
}
});
</script>
Page2.html:
<script>
var arr = JSON.parse(localStorage.getItem("deal_array"));
$.each(arr, function(i) {
console.log(arr[i]);
});
var msg = "Success !!!"
$.ajax({
url: '{% url 'ajax' %}',
type: 'GET',
data: arr,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
alert(msg);
}
});
});
</script>
/r/django
https://redd.it/6vp3hu
reddit
How can I get data fro QuerySet dict received via AJAX... • r/django
I have a model and want to create record based on the data recieved to my view from a AJAX call: In...
Jupytercon Notebooks?
Is there a place or could this be a place to post notebooks/resources from Jupytercon for those not able to attend?
/r/JupyterNotebooks
https://redd.it/6vk4q8
Is there a place or could this be a place to post notebooks/resources from Jupytercon for those not able to attend?
/r/JupyterNotebooks
https://redd.it/6vk4q8
reddit
Jupytercon Notebooks? • r/JupyterNotebooks
Is there a place or could this be a place to post notebooks/resources from Jupytercon for those not able to attend?
Need help with SQL-Alchemy
Hi, I am not sure if this make sense but I have two models, Person & Employee with respective persons and employees tables. I want to have it so that the employees table has a column that keeps track of the id of person who created it. Lastly, I would like to display rows from the employees table filtered by the column that was used to keep track of the id of the person who created it. How can I do this? An example would be helpful. Thanks
/r/flask
https://redd.it/6vcj0h
Hi, I am not sure if this make sense but I have two models, Person & Employee with respective persons and employees tables. I want to have it so that the employees table has a column that keeps track of the id of person who created it. Lastly, I would like to display rows from the employees table filtered by the column that was used to keep track of the id of the person who created it. How can I do this? An example would be helpful. Thanks
/r/flask
https://redd.it/6vcj0h
reddit
Need help with SQL-Alchemy • r/flask
Hi, I am not sure if this make sense but I have two models, Person & Employee with respective persons and employees tables. I want to have it so...
flask api and incremental testing
I am working on my first flask api, and I must test it because I'll be using it for a task that's rather sensitive. The issue is when I'm testing the CRUD part of the api I am not using unit tests which is bothering me as I ended up using incremental testing. Any tips or resources I could read to get an idea how to test CRUD operations with unit tests ?
/r/flask
https://redd.it/6qnd66
I am working on my first flask api, and I must test it because I'll be using it for a task that's rather sensitive. The issue is when I'm testing the CRUD part of the api I am not using unit tests which is bothering me as I ended up using incremental testing. Any tips or resources I could read to get an idea how to test CRUD operations with unit tests ?
/r/flask
https://redd.it/6qnd66
reddit
flask api and incremental testing • r/flask
I am working on my first flask api, and I must test it because I'll be using it for a task that's rather sensitive. The issue is when I'm testing...
[D] Andrew Ng's "Structuring a ML Project" summary in a diagram
https://medium.com/@erogol/designing-a-deep-learning-project-9b3698aef127
/r/MachineLearning
https://redd.it/6vplgr
https://medium.com/@erogol/designing-a-deep-learning-project-9b3698aef127
/r/MachineLearning
https://redd.it/6vplgr
Medium
Designing a Deep Learning Project
There are numerous on-line and off-line technical resources about deep learning. Everyday people publish new papers and write new things…
I wrote LaTeXiPy, a package which allows you to easily generate plots in multiple formats, and can play well with LaTeX!
https://github.com/masasin/latexipy
/r/Python
https://redd.it/6vpcnf
https://github.com/masasin/latexipy
/r/Python
https://redd.it/6vpcnf
GitHub
GitHub - masasin/latexipy: Generate beautiful plots for LaTeX using your existing matplotlib-based code.
Generate beautiful plots for LaTeX using your existing matplotlib-based code. - masasin/latexipy
Prevent modification of model through model/manager/queryset methods
Hello everybody,
I have a model which needs complex logic for update, creation and deletion.
I would like to have only one custom manager method to handle creation (let's call it `new`), one model method to handle deletion and prevent all the others.
My question is : Is there other methods that can modify models besides the ones below? Is there any way to know if I'm not missing a method that can modify models (other than reading the whole documentation)?
Here is what I have now :
class MyModelQuerySet(models.QuerySet):
def update(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def delete(self):
raise ValueError("Use 'delete' method from model instead.")
class MyModelManager(models.Manager):
def get_queryset(self):
return MyModelQuerySet(self.model, using=self._db)
def create(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def get_or_create(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def update_or_create(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def new(self, *args, **kwargs):
obj = self.model()
# Insert complex logic here
super(MyModel, obj).save()
class MyModel(models.Model):
def save(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def delete(self, *args, **kwargs):
# Insert another complex logic here
super().delete(*args, **kwargs)
Thanks in advance for any bit of advice!
/r/django
https://redd.it/6vrbhy
Hello everybody,
I have a model which needs complex logic for update, creation and deletion.
I would like to have only one custom manager method to handle creation (let's call it `new`), one model method to handle deletion and prevent all the others.
My question is : Is there other methods that can modify models besides the ones below? Is there any way to know if I'm not missing a method that can modify models (other than reading the whole documentation)?
Here is what I have now :
class MyModelQuerySet(models.QuerySet):
def update(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def delete(self):
raise ValueError("Use 'delete' method from model instead.")
class MyModelManager(models.Manager):
def get_queryset(self):
return MyModelQuerySet(self.model, using=self._db)
def create(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def get_or_create(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def update_or_create(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def new(self, *args, **kwargs):
obj = self.model()
# Insert complex logic here
super(MyModel, obj).save()
class MyModel(models.Model):
def save(self, *args, **kwargs):
raise ValueError("Use 'new' method from manager instead.")
def delete(self, *args, **kwargs):
# Insert another complex logic here
super().delete(*args, **kwargs)
Thanks in advance for any bit of advice!
/r/django
https://redd.it/6vrbhy
reddit
Prevent modification of model through... • r/django
Hello everybody, I have a model which needs complex logic for update, creation and deletion. I would like to have only one custom manager...
Created this web application using Flask. Please let us know your reviews about it.
https://pageone.herokuapp.com
/r/flask
https://redd.it/6vsean
https://pageone.herokuapp.com
/r/flask
https://redd.it/6vsean
JQuery dropdown menu not working
I am in the middle of creating a very basic website and would like to use a drop down menu in the navigational bar.
I have included the Javascript library above my code but the dropdown fails to open when I click on it. You notice I have it in 2 places at the moment to see if it would work if I placed it in the head section but it doesn't make a difference.
I am just running it through my command line at the moment if that matters.
My code can be found here: https://pastebin.com/4qShX7zG
Thanks!
/r/flask
https://redd.it/6vsl1p
I am in the middle of creating a very basic website and would like to use a drop down menu in the navigational bar.
I have included the Javascript library above my code but the dropdown fails to open when I click on it. You notice I have it in 2 places at the moment to see if it would work if I placed it in the head section but it doesn't make a difference.
I am just running it through my command line at the moment if that matters.
My code can be found here: https://pastebin.com/4qShX7zG
Thanks!
/r/flask
https://redd.it/6vsl1p
Pastebin
[HTML] <script src="h - Pastebin.com