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
Foreign key option

I am making an app for a BJJ tournament. I have a form to catch competitors' registration like name, weight, and rank. After that, the admin will create however many groups for competition as needed. Each competitor can only be in 1 group.

Models.py

class Group1(models.Model):
grouplabel = models.CharField(maxlength=20, unique=True)
point = models.IntegerField(default=0)


class Competitors(models.Model):
flname = models.CharField(maxlength=255)
Weight = models.IntegerField(validators=[MinValueValidator(50), MaxValueValidator(300)])
rank = models.CharField(max
length=255)
Group1 = models.ForeignKey(Group1, blank=True, null=True, ondelete=models.CASCADE, tofield='grouplabel')


[
Admin.py](https://Admin.py)

&
#x200B;

class MemberAdmin(admin.ModelAdmin):
list
display = ("flname", "Weight", "rank", "Group1")
admin.site.unregister(Competitors)
admin.site.register(Competitors, MemberAdmin)

def str(self):
return f"{self.flname} {self.Weight}"


class MemberAdmin(admin.ModelAdmin):
listdisplay = ("grouplabel","point")
admin.site.unregister(Group1)
admin.site.register(Group1, MemberAdmin)


​

Here, we can

/r/djangolearning
[https://redd.it/13fun0n
Help me

/r/IPython
https://redd.it/13fvyw7
Help me

/r/IPython
https://redd.it/13fvt97
Flask: Uploading pdfs to google drive using its API

for file in files:
filemetadata = {
'name' : secure
filename(file.filename),
'parents' : folder_id
}

#f = io.BytesIO(file)

media = MediaFileUpload(file, mimetype = 'application/pdf')

drive.service.files().create(
body = filemetadata,
media
body = media,
fields = 'id'
).execute()

So here's the part that I can't figure out. What is basically happening is that I have a form that takes in a list of pdf files (max 5 mb for each of those files) but what I can't figure out is how to upload those files to the google drive folder. I

/r/flask
https://redd.it/13gcndv
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?

Use this thread to chat about and share Python resources!

/r/Python
https://redd.it/13g1e22
Do You Use Singletons?

I work on a monolith that needs to maintain many connections (SQL ODBC, HTTP, Redis, etc...) and I find myself worrying about connection management often. The monolith also has much of its functionality in a gunicorn/uvicorn/starlette server.

I often find myself wondering if I should implement singleton connection management classes for many of these connections. I'm aware that they don't work across multiple gunicorn workers, but at least I know there's only one aiomysql pool per worker, for example. Does anyone use singletons for this purpose, or is there a better design pattern that I'm not using?

/r/Python
https://redd.it/13g4ml1
Generate Django templates with JS

https://github.com/LazerRaptor/django-template-gen/

I've been working on a Rollup.js plugin on the last few weekends that would generate Django templates from JS modules. It utilizes Rollup hooks that give access to source code (as a string) and AST, which makes it possible to pick certain bits of code. In this case, I needed to get render() method's return value, which is hyperscript that can be transpiled into HTML. The plugin lives here.

This is just an example project so far. The end goal is to bring the DX of node.js frontend libraries to the Django's ecosystem. For me, the functionality of Alpine.js and HTMX is great, but the DX is the biggest problem. I can't help but create a mess using them. There are projects like django-components and slippers that help to some extent. But I believe there is more potential for DX improvements if we move all our frontend work in node.js environment.

I'd appreciate if you had a quick look at the project's readme and shared your thoughts.

/r/django
https://redd.it/13gj12x
P New tokenization method improves LLM performance & context-length by 25%+

I've been working on this new tokenization method to optimally represent text with fewer tokens than current methods. It's MIT licensed.

Code at Github.

Test it out.

The general-english-65535 vocabulary, and the code versions are already complete. The general-english-32000 should be finished within a few hours. Then I'm going test a non-greedy version which should do even better.

Intro from README:

tokenmonster is a novel approach to tokenization with broad-ranging use potential, but its primary motivation is to increase the inference speed and context-length of large language models by choosing better tokens. By selecting more optimal tokens, text can be represented with 20-30% less tokens compared to other modern tokenizing methods, increasing the speed of inference, training and the length of text by 20-30%. The code-optimized tokenizers do even better, see it for yourself.

I also believe that tokenmonster vocabularies will improve the comprehension of Large Language Models. For more details see How and Why.

## Features

Longer text generation at faster speed
Determines the optimal token combination for a greedy tokenizer (non-greedy support coming)
Successfully identifies common phrases and figures of speech
Works with all languages and formats, even binary
Quickly skims over HTML tags, sequential spaces, tabs, etc. without wasting context
Does not require normalization

/r/MachineLearning
https://redd.it/13gdfw0
Best SAAS stack and template for building quick MVPs?

I want to learn a new stack. All I need is a template with authentication (firebase ideally), payment processor (like stripe), and database. Any God-tier tutorial, repo, or stack you know of? I really like Flask but I am wondering if other web frameworks allow you to do things quicker and plug things in quicker. I am hearing a lot about Next.js but yeah… not sure what to go for. All I want is a template that I can use multiple times to spam MVP after MVP. A one page presenting the product, login / logout system, some tokens given to the user and an API call to midjourney or ChatGPT that provides the thing the customer is paying for.

/r/flask
https://redd.it/13gm2ak
Google Sign in AllAuth

Hey yall So i configured google and django allauth and I have successfully gotten to the sign in page for google but once I click on a gmail account I want to log in as I get a

This site can’t be reached localhost refused to connect.

Idk if its because the site was connected to the social account in the admin panel or what? I would connect the site and google but it doesn't pop up only groups, users, social accounts. any ideas?

/r/django
https://redd.it/13go7a4
Architecting Django allauth with Multi-Tenant Schemas

Hello everyone,

I am currently working on a Django project that implements a multi-tenancy architecture using the Django Tenants library. The purpose is to provide data isolation between different tenants in the system, each having its own set of schemas.

However, I am facing a critical architectural decision concerning the integration of Django allauth within this multi-tenant system. The issue arises from the fact that Django allauth inherently depends on the User model.

The challenge here is how to implement Django allauth in such a system. If I make Django allauth tenant-specific, each tenant would have its own registration and login pages, and users would need to register separately for each tenant they want to access. This also means that the same email could be used to create different accounts on different tenants, and there would be no option to share authentication or user information between tenants.

On the other hand, if I make Django allauth shared (not tenant-specific), then it becomes a challenge to manage user-tenant relationships and ensure data isolation since the User model would need to be accessible across all schemas.

I am seeking advice on the best way to implement Django allauth in a multi-tenant Django application. Has anyone faced a

/r/django
https://redd.it/13gp2g6
R Enhancing Language Model Performance through Context Preservation: A Novel Approach Utilizing Internal State Symbols

Abstract

In the domain of conversational AI, the quality of output generated by large language models (LLMs) is of significant importance. This paper explores a novel approach to provide context and improve the quality of LLM responses in conversational settings. The proposed technique involves instructing the LLM to output a series of symbols representing its internal state at the end of its last response, which encapsulates the context and process that led to that answer. When provided with symbols from the user's previous conversation, the LLM can restore its internal state before reviewing the newly-received message, thus enabling it to understand the context of the entire conversation better. Although a quantitative analysis has not been conducted, subjective evaluations reveal evident improvements in the quality of responses, drawing parallels with human conversation dynamics.

1. Introduction

As artificial intelligence (AI) technologies continue to advance, LLMs have emerged as essential tools in the development of conversational AI systems. While these models are capable of producing impressive results, their performance can be further enhanced by providing additional context in conversational settings. This paper presents a novel approach to augment LLMs with context by leveraging their internal state representations, and discusses the potential benefits of this method in

/r/MachineLearning
https://redd.it/13gsqkl
OC Python Cheat Sheet in PCB design

I have created a Python Cheat Sheet and would like to collect feedback from you. If you want to have a cheat sheet as a real PCB, just take a look. I would be very happy if you support my project. I'm happy to answer any questions :)

https://www.westartfactory.com/#python

Python Cheat Sheet in PCB design

​

Python cheat sheet from a real circuit board - Front

Python cheat sheet from a real circuit board - Back

/r/Python
https://redd.it/13gpfiu
Sqlalchemy help

I’m currently teaching myself sqlalchemy and I’ve made a website where users can log on and create a video game library using the igdb api.
I’ve created a database that stores all the “user” data, and I have a separate database to store the “game” data. At this point all the users share the same “game” database. I’d like each user to only be able to access their own game library but I can’t figure out how to do it or what to search to learn how to do it. Can anyone point me in the right direction?

/r/flask
https://redd.it/13geo76