Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
I couldn't find much resources on how to write tests against Elasticsearch in Django, so I wrote up a guide.

Like the title says, I couldn't find much resources on how to write tests against Elasticsearch in Django, so I figured I'd write something up after I got it working.

https://yanglinzhao.com/posts/test-elasticsearch-in-django

I hope others who have a similar tech stack find it useful.

/r/django
https://redd.it/igyyma
Hosting custom-domain Flask based web app

I want to host my Flask web application but don’t know where to go. Maybe Google Cloud Platform, AWS or Pythonanywhere are a valid option? How to figure out the most efficient and budget-friendly company?

/r/flask
https://redd.it/ih4wk6
New hosted Notebooks

Hi all, we currently use an in house jupyter solution, but we started exploring new options. We see AWS sagemaker and AI Platform Notebooks in Google. We have large amount of data in BigQuery, so.the obvious choice seems to be GCP, but hesitant as the support hasn't been great experience so far with BQ specially many libraries changes which are always breaking, so not sure if GCP is the right option any ideas?

/r/JupyterNotebooks
https://redd.it/igqyco
Looking For: Exemplar Django Project

I'm wondering if anyone has a suggestion for an existing Django project that you'd consider to be really well put together / has lots of interesting examples?

I know all about Cookie Cutters, what I'm talking about more is if there are any sites / projects on Git that you ever look at to see an example of organizing code or a complicated architecture.

/r/django
https://redd.it/ihb99s
Juypter Notenotebooks.ai module error

Hi everyone

I'm a newbie trying to use Jupyter [notebooks.ai](https://notebooks.ai) I am able to import pandas, and other modules no problem. But everytime I attempt to *import geopandas as gpd* I get this error ModuleNotFoundError: No module named 'geopandas. Has anyone else had similar trouble? I am just a newbie to the juypter [notebooks.ai](https://notebooks.ai) and python coding in general so there's probably something simple that I am missing. Any help would be appreciated.

/r/JupyterNotebooks
https://redd.it/ihegst
How do you encrypt customer data?

I'm curious how you guys encrypt customer data using Django and Postgres. By Customer data I mean data which is owned by a customer of your website which could be considered sensitive such as passwords or financial information (like revenue or cost).

/r/django
https://redd.it/ih7mgq
How to get objects with certain foreignkey relationships in ORM?

Assume we have a product model:

`class Product(models.Model):`

`name = models.Charfield()`And a property model where possible properties are defined (like "price", "color", "weight"...):

`class Property(models.Model):`

`name = models.CharField()`

And we keep product properties in a separate model:

`class ProductProperty(models.Model):`

`propery = models.ForeignKey(Property)`

`product = models.ForeignKey(Product)`

`value = models.Charfield()`

I want to get product objects which have certain properties. For instance, **I want to get objects only if "price" and "color" is defined for them in ProductPropery table.**

I obtain the required properties as objects, but I could not solve how can I get products that have all of the given properties.

To rephrase, I'm looking for something like this:

`properties = Property.objects.filter(Q(name__contains="Price") | Q(name__contains="Color")) #this could return one or multiple property objects`

​

`products = properties.productproperty_set.product_set # imaginary line I made up to show what I want to get`

I could only think of: looping through properties and sub-loop for related ProductProperties to get their products and create multiple lists, and then create a list that's made of common elements (products that are included in each list)

It would be great if you could help,

Best wishes

/r/django
https://redd.it/ihhszo
Would I need the rest framework to do something like /review/bandname instead of /review/1?

Hopefully my title makes sense. As a learning project, I'm making a Django app that you can review bands. I was wondering how to make the url have the band name in it instead of the primary key. 127.0.0.0:8000/review/metallica instead of 127.0.0.0:8000/review/1

/r/djangolearning
https://redd.it/ihdot3
How to get objects with certain foreignkey relationships in ORM?

Assume we have a product model:

`class Product(models.Model):`

`name = models.Charfield()`

And a property model where possible properties are defined (like "price", "color", "weight"...):

`class Property(models.Model):`

`name = models.CharField()`

And we keep product properties in a separate model:

`class ProductProperty(models.Model):`

`propery = models.ForeignKey(Property)`

`product = models.ForeignKey(Product)`

`value = models.Charfield()`

I want to get product objects which have certain properties. For instance, **I want to get objects only if "price" and "color" is defined for them in ProductPropery table.**

I obtain the required properties as objects, but I could not solve how can I get products that have all of the given properties.

To rephrase, I'm looking for something like this:

`properties = Property.objects.filter(Q(name__contains="Price") | Q(name__contains="Color")) #this could return one or multiple property objects`

​

`products = properties.productproperty_set.product_set # imaginary line I made up to show what I want to get`

I could only think of: looping through properties and sub-loop for related ProductProperties to get their products and create multiple lists, and then create a list that's made of common elements (products that are included in each list)

It would be great if you could help,

Best wishes

/r/django
https://redd.it/ihisa1
DS Slideshow, My first Flask/ Python Project.

Hi, I'm an 18 year old college student going into university this year! I've been working on a small Flask based app for a while now and I think its about ready to share! I created a simple lightweight digital signage application for use on a Raspberry Pi or similar. It works by hosting a website on the host machine which you can then access from any number of other screens to display your slideshow.

This is a passion project for me, I intern at a small company that was looking for a digital signage solution for their office. They were not satisfied with any of the applications on the market so I volunteered to see what I could come up with. After a couple of days, I had a simple HTML and JS webpage that you could drop images into a file and they would rotate on a slideshow. Although this was all that was required by the company, I continued to develop this software on my own time and I'm really happy with how it's turning out!

Features:

* Currently there is support for Images and Webpages with video support coming soon!
* Login page to ensure nobody alters the slides without

/r/flask
https://redd.it/ihjqnp
[P] GenRL: PyTorch-First Reinforcement Learning library centered around reproducible and generalizable algorithm implementations

Github: [https://github.com/SforAiDl/genrl](https://github.com/SforAiDl/genrl)

Check out the [documentation](https://genrl.readthedocs.io/) and [tutorials](https://genrl.readthedocs.io/en/latest/usage/tutorials/index.html).

Reinforcement learning research is moving faster than ever before. In order to keep up with the growing trend and ensure that RL research remains reproducible, GenRL aims to aid faster paper reproduction and benchmarking by providing the following main features:

* **PyTorch-first**: Modular, Extensible and Idiomatic Python
* **Unified Trainer and Logging class**: code reusability and high-level UI
* **Ready-made algorithm implementations**: ready-made implementations of popular RL algorithms.
* **Faster Benchmarking**: automated hyperparameter tuning, environment implementations etc.

By integrating these features into GenRL, we aim to eventually support **any new algorithm implementation in less than 100 lines**.

Currently, the library has implementations of popular classical and Deep RL agents that ready to be deployed. Apart from these, various Bandit algorithms are a part of GenRL. It has various abstraction layers that make the addition of new algorithms easy for the user.

The library aims to add other key research areas like Multi-agent RL, Evolutionary RL and hyperparameter optimization and provide extensive support for distributed training of agents.

**We are looking for Open Source Contributors.**

/r/MachineLearning
https://redd.it/ihhtiw
Bare essential javascript to learn to help with flask

I feel that recently lack of ability to interact with dom is getting in the way of me communicating between back and front-end. (ofc, I could be entirely wrong too)

i really want to focus on python and flask at this period but am ope to invest time to JS to help with that journey. I am building things for myself so do not need to achieve anything fancy.

In order for me to make the most of that time what subjects should I focus on? (I hear eloquent is a good book)

Thank you for helping/reading

/r/flask
https://redd.it/ihgum3
Thursday megathread: Python careers!

Discussion of using Python in a professional environment, getting jobs in Python and more!

**This thread is not for recruitment, please see** r/PythonJobs **or the thread in the sidebar for that.**

/r/Python
https://redd.it/ihaiio
Django admin: adding objects for foreignkey from other side

so I have these two models:

class Recipe(models.Model):
short_description = HTMLField(max_length=400)
likes = models.ManyToManyField(User, blank=True,
related_name='recipe_likes')
slug = models.SlugField(blank=True, unique=True)
published_date = models.DateTimeField(blank=True, default=datetime.now)
ratings = GenericRelation(Rating, related_query_name='recipes')

class Ingredient(models.Model):
name = models.CharField(max_length=20)
amount = models.FloatField()
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE,


/r/django
https://redd.it/ihij82
Are my tests okay?

I read on Two Scoops of Django that you should test the following aspects of your models:

>Two Scoops of Django 3.x
>
>Models: Creating/updating/deletingofmodels,modelmethods,modelmanagermethods.

however, there is not an example of how to do it with pytest, is my approach correct for these tests?

​

models.py

from model_utils.models import TimeStampedModel
import uuid

# from mysocialbeer.accounts.models import Account
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.urls import reverse


class Post(TimeStampedModel):
"""
This is the model that represent posts in MySocialBeer
"""

uid = models.UUIDField(default=uuid.uuid4())
title = models.CharField(verbose_name=_("Title"), max_length=50)
body = models.TextField(verbose_name=_("Body"))
latitude = models.FloatField(verbose_name=_("Latitude"))


/r/djangolearning
https://redd.it/ihskvi
Friday megathread: Free chat Friday!

Use this thread to talk about anything Python related! Questions, news, projects and any relevant discussion around Python is permitted!

/r/Python
https://redd.it/ihwl4s
Is there a better way to handle unexpected view errors.

What I do is, I add a middleware so that in case the view function raises an unhandled exception the default Django response is overridden by my specified response, see the following code snippet.


class ErrorHandlingMiddleware:
"""
The purpose of this middleware is to handle unexpected errors in the requests and
provide a user friendly error response.
"""

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)
return response

@staticmethod
def process_exception(request, exception):
if settings.DEBUG:


/r/django
https://redd.it/ihznwr