Telegram Group Search
Copy model instance to prefill form?

I am making a recipe application. I want to be able to copy an existing recipe and make edits to create a new recipe. How I can prefill a form/edit view using an existing model instance and then save the data into a new model instance?

Here is my current model structure, it's implementation assumes that a recipe is composed of pre-existing ingredients and, potentially, other user generated recipes.


Models.py

class Ingredient(models.Model):
"""Base ingredient class"""
name = models.CharField(max_length=500)
...

class Recipe(models.Model):
"""Base recipe class containing instructions and description"""
name = models.CharField(max_length=500)
...
ingredients = models.ManyToManyField(Ingredient, through='RecipeIngredient')
sub_recipes = models.ManyToManyField('self',


/r/django
https://redd.it/1dq7jrh
Friday Daily Thread: r/Python Meta and Free-Talk Fridays

# Weekly Thread: Meta Discussions and Free Talk Friday 🎙️

Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!

## How it Works:

1. Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
2. Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
3. News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.

## Guidelines:

All topics should be related to Python or the /r/python community.
Be respectful and follow Reddit's Code of Conduct.

## Example Topics:

1. New Python Release: What do you think about the new features in Python 3.11?
2. Community Events: Any Python meetups or webinars coming up?
3. Learning Resources: Found a great Python tutorial? Share it here!
4. Job Market: How has Python impacted your career?
5. Hot Takes: Got a controversial Python opinion? Let's hear it!
6. Community Ideas: Something you'd like to see us do? tell us.

Let's keep the conversation going. Happy discussing! 🌟

/r/Python
https://redd.it/1dq60v8
How to not write atrocious APIs with Django Rest Framework?

I recently wrote an API with django which does a lot of things, and it got me thinking that I really have a big gap in my django/ django rest framework knowledge. It is basically creating User instances for a staff user. The API is supposed to take role and different subject ids which will be used for the SubjectTeachers model. Then, after creating a user, it sends email to the user's email through a celery task. It also handles email already being sent, and just resends it based on if the user changed their password or not.


The thing is, I don't think I'm handling this in any good way. There are no use of serializers, functions, just a big ass function doing a lot of things. I want to know how would you handle it in a proper way, following proper conventions provided by django and django rest framework. There is no proper error handling, half ass validations.

Please provide me with your insights, resources on how I should properly approach building APIs with django rest framework, and how this API should have been created.

```python

class InviteStaffApiView(APIView):


/r/django
https://redd.it/1dps3lu
FastCRUD - powerful CRUD methods and automatic endpoint creation for FastAPI

**What My Project Does**

**FastCRUD** is a Python package for **FastAPI**, offering robust async CRUD operations and flexible endpoint creation utilities, streamlined through advanced features like **auto-detected join** conditions, **dynamic sorting**, and offset and cursor **pagination**.

We recently reached 450 Stars on Github and Over 24k Downloads! With more users joining our community, there's a lot of work ahead. Whether you're a fan of Python, FastAPI, or SQLAlchemy, or just interested in contributing to open-source projects, we'd love your help!

You can contribute by:

* Opening issues
* Finding and reporting bugs
* Testing new features
* Improving documentation
* Fixing bugs
* Adding new features
* Creating tutorials


**Target Audience**

People who currently use or are interested in FastAPI with SQLAlchemy and SQLModel

**Comparison**

For the endpoint part, there's [FastAPI CRUD](https://github.com/awtkns/fastapi-crudrouter) router, but it's unmaintained (does not support Pydantic V2), for the CRUD methods the alternative would be writing from scratch.


GitHub: [https://github.com/igorbenav/fastcrud](https://github.com/igorbenav/fastcrud)

Docs: [https://igorbenav.github.io/fastcrud/](https://igorbenav.github.io/fastcrud/)

/r/Python
https://redd.it/1dq7af3
Django Middleware unable to process

I have a django project in which I am using two custom middlewares.

One of the middewares is called AuthorizationMiddleware

class AuthorizationMiddleware:
def init(self, getresponse=None):
self.get
response = getresponse

def process
view(self, request, viewfunc, viewargs, viewkwargs):
view
name = '.'.join((viewfunc.module, viewfunc.name))

if viewname in EXCLUDEFROMMIDDLEWARE:
return None

def call(self, request):
token = request.headers.get("Http-Authorization")
if token:
request.META[AUTHENTICATION
HEADER] = f'{token}'


/r/django
https://redd.it/1dqg551
Scraping Ecommerce Platforms Using Python

The online retail or e-commerce industry has seen a fast pace of growth since its launch. This boom is also witnessing the rise of 10-minute delivery models, revolutionizing how customers interact with e-commerce platforms. 

This article will explore how to scrape data from e-commerce platforms using Python.

Ream More: https://ecommerceapi.io/blog/scraping-e-commerce-platforms-with-python/

/r/Python
https://redd.it/1dqgxds
What's better memorizing codes or understanding them deeply?

I'm new to python and I'm just wondering is my strat of learning 2 syntax a day and spending maybe 1 hour learning them and understanding them. better than just memorizing them?

/r/Python
https://redd.it/1dqivtw
Error while finding module specification for 'flask.__main__' (ImportError: cannot import name 'Flask' from partially initialized module 'flask' (most likely due to a circular import)

I have this error and I have no idea how to fix it. My app.py file has the following code:

import os
from flask import Flask, render_template, session, redirect, url_for
from dotenv import load_dotenv
from users import user_bp

load_dotenv()

app = Flask(__name__)
app.secret_key = os.environ.get('FLASK_LOGIN_SECRET_KEY')
app.register_blueprint(user_bp)

Can someone point me in the correct direction please?

/r/flask
https://redd.it/1dqi916
Flask with Mobile App Development

I have recently finished my first website ever with flask and really enjoyed the framework as a whole. As i have just finished that project i want to try something new in making a mobile app and was curious to know if anyone has any experience doing so and what they used to make it like a front end in flutter or something similar.

/r/flask
https://redd.it/1dqodnh
Newly uploaded Python talks from Pycon Sweden 2024 and Pydata London 2024

Hello again r/Python!

I've recently published the newest issue of Tech Talks Weekly newsletter that I'm building and I noticed that this time around there are plenty of fresh talks from two major Python conferences: PyCon Sweden 2024 and PyData London 2024. I decided to repost them here, so here we go:

# 1. PyCon Sweden 2024

1. **"Debugging Python by Juha-Matti Santala"** ⸱ +100 views ⸱ 26 Jun 2024 ⸱ 00h 25m 41s
2. **"Lightning talks"** ⸱ <100 views ⸱ 26 Jun 2024 ⸱ 00h 42m 15s
3. **"Python Developer Experience with Polylith by David Vujic"** ⸱ <100 views ⸱ 26 Jun 2024 ⸱ 00h 32m 40s
4. **"GraphQL as an umbrella for microservices by Artur Smęt"** ⸱ <100 views ⸱ 26 Jun 2024 ⸱ 00h 32m 10s
5. **"Load testing with Python and Locust by Lars Holmberg"** ⸱ <100 views ⸱ 26 Jun 2024 ⸱ 00h 30m 17s
6. **"CALFEM - Teaching the Finite Element method in Python by Jonas Lindemann"** ⸱ <100 views ⸱ 27 Jun 2024 ⸱ 00h 35m 34s
7. **"Closing remarks of PyCon Sweden 2023"** ⸱ <100 views ⸱ 26 Jun 2024 ⸱ 00h 23m 02s
8. **"Opening Talk by PyCon Chairman, Alexander Hultner"** ⸱ <100 views ⸱ 26 Jun 2024 ⸱ 00h 11m

/r/Python
https://redd.it/1dqnhfv
Atollas - a column level type system for pandas

Hey folks!

I do a lot of stuff professionally with pandas and dask, and I always reeeeaaaly wish that they had a column level type system. I feel like a lot of bugs like, one-to-one joins on non unique columns, or just plain old incorrect source data would be quicker to find if there was one.

So I've written one - or at least started to. It's pretty early stage, but I'm pretty excited about it as an idea. Would love some feedback people (especially ones that work with pandas a lot)!

So here's my little project, hope it's interesting to someone!


## What my Project Does

Provides a column level type system for pandas, to catch bugs earlier and check for things like, join operation validity.

## Target Audience

People looking to put pandas code into production with better reliability that pandas provides out the box.

## Comparison

I don't know of any 1-2-1 comparison, things like polars have good type checking internally, but don't make any attempt to type check columns. Pandera is the closest project, which gives a decorator to enforce schemas at type boundaries)


/r/Python
https://redd.it/1dqm1y4
Thoughts on Teaching Python to Children

MIT's Scratch is a very successful online environment for teaching kids to program. The statistics give an idea of how popular it is - for example, 36 million unique visitors last month.

It enables visitors to create stories using a visual "drag-and-drop" language and to post their creations to a public gallery. It also allows creators to add "remix" code from other students as well.

The "Scratch" programming language has no commercial uses that I am aware of, so people must be visiting the site just for the pure pleasure of learning to program and sharing what they produce with others.

There is a wide age distribution of ages of the people visiting the Scratch site but there is a peak at about age 12 after which it falls quite rapidly.

I think that there are several reasons for the popularity of Scratch:

1. it is easy to learn and understand
2. there is nothing to install or set up
3. you can start by modifying existing examples
4. you can share what you have created by simply pressing "Save"
5. stories can be visually exciting with lots of animation effects
6. Scratch is written in JavaScript and can run on mobile devices

When comparing this to Python, I

/r/Python
https://redd.it/1dqstt2
I have spent all day trying to upload an image from a form. Please help

settings.py:

STATIC_URL = 'static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")
]

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'


forms.py:

class SignUp(forms.Form):
is_doctor = forms.BooleanField(label = "Are you a doctor?",required=False)
f_name = forms.CharField(label = "First Name", max_length=200)
l_name = forms.CharField(label="Last Name",max_length=200)
username = forms.CharField(label = "Username",max_length = 100)
email = forms.CharField(label = "Email",max_length=200)
profile_pic = forms.ImageField(label= "Profile Picture", widget = forms.ClearableFileInput(attrs= {'class':'form-control'}))
password = forms.CharField(label ="Password",max_length=200)
confirm_password = forms.CharField(label = "Confirm Password",max_length=200)
address = forms.CharField(label="Address",max_length = 400)

views.py:

def signup(response):
if response.method == "POST":
form = SignUp(response.POST,response.FILES)


/r/djangolearning
https://redd.it/1dqv3xw
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

# Weekly Thread: Resource Request and Sharing 📚

Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!

## How it Works:

1. Request: Can't find a resource on a particular topic? Ask here!
2. Share: Found something useful? Share it with the community.
3. Review: Give or get opinions on Python resources you've used.

## Guidelines:

Please include the type of resource (e.g., book, video, article) and the topic.
Always be respectful when reviewing someone else's shared resource.

## Example Shares:

1. Book: "Fluent Python" \- Great for understanding Pythonic idioms.
2. Video: Python Data Structures \- Excellent overview of Python's built-in data structures.
3. Article: Understanding Python Decorators \- A deep dive into decorators.

## Example Requests:

1. Looking for: Video tutorials on web scraping with Python.
2. Need: Book recommendations for Python machine learning.

Share the knowledge, enrich the community. Happy learning! 🌟

/r/Python
https://redd.it/1dqy1qp
Flask Migrate issues

Hi,

I recently started reading the "Learning Flask Framework 2nd Edition" ebook from Packt publishing, the major issue seems to be that the book is from 2015 and the flask frameworks have evolved over time to the point that some of the code won't work without tweaks. One of the issues I have is with Flask Migrate, I can't seem to get it to work, It complains about not being able to import certain modules, not sure if it's a circular dependancy or what but even if flask db migrate succeeds, it generates drop table statements that nukes the database if you do a flask db upgrade.

It's quite difficult to fix for a noob at Python / Flask. Wondering if anyone can suggest some fixes? If I need to post a zip of my folder structure I can find a way to do that - I've being trying all sorts so there might be some junk in the source files.

Thanks in advance.

/r/flask
https://redd.it/1dqtdvc
What's the best practice for scaling a Django app?

What's the best practice for scaling a Django app?


• Django + Elastic Beanstalk

• Django + Docker + Fargate

• Django + Kubernetes + Docker + EKS

Have you guys tried all three? which one works the best when handling a large amount of traffic?

/r/django
https://redd.it/1dqwmww
How to Master Django

I am a beginner to backend development and databases,

I followed a few tutorials and built a blog app and chat app.

I was trying to build an e-commerce website backend using Django and PostgreSQL on my own but I'm messing up everything.

Please list good resources to learn Django and backend development.



/r/django
https://redd.it/1dr5m91
PSQLPy - Asynchronous Python PostgreSQL driver written in Rust

Hello everyone. We want to present you PSQLPy: our new project that allows communicate with PostgreSQL. Conceptually it's similar to psycopg or asyncpg but fully written in Rust and type hints support.

What Our Project Does
- Make an interaction with the PostgeSQL in your application much faster (2-3 times).
- Be sure that there won't be any unexpected errors.
- Don't usually go to the documentation to search every question - we have awesome docstrings for every component.
- Use MyPy (or any other Python type checker) with confidence that exactly the types specified in the typing will be returned.
- Concentrate on writing your code, not understanding new abstractions in this library, we only have classes which represents PostgreSQL object (transaction, cursor, etc).

Target Audience
The driver is completely ready for production use, supports high-load and fault-tolerant systems

Comparison
We conducted a huge number of benchmarks.
The results are very promising! PSQLPy is faster than AsyncPG at best by 2 times, at worst by 20%. PsycoPG is 3.5 times slower than our new driver in the worst case, 60% in the best case.

Links:

Github repo: https://github.com/qaspen-python/psqlpy

Docs: https://qaspen-python.github.io

We would be pleased to see valuable feedback.
Best regards, PSQLPy team.

/r/Python
https://redd.it/1dqybfa
2024/06/29 11:52:58
Back to Top
HTML Embed Code: