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
building flask-sqlalchemy model from preexisting table

is there a way to use existing columns from a pandas dataframe to "automatically" generate a model/table? im trying to store output that consists of thousands of columns (flattened chroma feature data). i assume theres a way to declare characteristics other than manually, but im new to this - perhaps going about this the wrong way. thanks for any help!

/r/flask
https://redd.it/aziwf1
Can I use OneToOneField to break up a large modal into smaller related categories?

Say for example a Book class. It has your usual name author year publisher pages isbn fields. But then it also has fields like cover_image author_image publisher_logo etc that you could regroup in a related model BookImages. And it has stuff like critics_review awards accolades back_cover_quotes review_score etc that you could categorize under a model BookReview.

And likewise for any other fields that you could group under a model that would be related to the main Book Model with a OneToOneField.

Is this a valid use case? Or is it fine to just have like 40 attributes for a model.



/r/django
https://redd.it/azjb69
Django with Tornado does a good work like node.js, for real-time chats?

I was looking at a book for startups, just out of curiosity, at one point, the author says that the node is preferable to things like chat online, being an asynchronous back end and everything. But I also saw in other Django books, the authors mention Django Channels and Tornado for chats, but I have not yet seen how to integrate.

​

In terms of performance and scalability, is there any difference between a back-end chat made with node / express and one done with Django and Tornado?

/r/djangolearning
https://redd.it/azhydl
How to add an object and display at the same instant without hard refresh?

I want, for example, to add a post, but the same page that it adds, is the same one that displays all others.

How do I submit a post and display it in my html at the same time? should I use DOM for this? I already did this with DOM and LocalStorage, but in the case of django; I need to submit a form, and depending on the response, add it to the database and display in the browser at the same time.

I already researched ajax but I did not quite understand.

/r/djangolearning
https://redd.it/azctri
Django project structure question

I recently started developing django apps and I'm wondering the best project structure.

More specifically, do you put a data access layer in your django projects that contain all of your migrations? is that the best practice?

Anyway, what are some good design practices for a django project with multiple apps?

/r/django
https://redd.it/azp7i3
RelatedObjectDoesNotExist: User has no "usertype"

I am having issues with Django defining a custom user, which in this case is "cust" (short for customer) in Django 2.1. I have several other user types which contain separate registration forms to register them as a specific user type. I have built this from the tutorial *"How to Implement Multiple User Types with Django"* by Vitor Freitas, which eliminates Django's default user management system. My goal is to have a protected view (customer hub) which only customers can enter, and so on for other user types.

​

My traceback error, respectively, is:

**RelatedObjectDoesNotExist at /companyusers/cust/**

**User has no cust.**

/r/django
https://redd.it/azu965
[N] OpenAI LP

"We’ve created OpenAI LP, a new “capped-profit” company that allows us to rapidly increase our investments in compute and talent while including checks and balances to actualize our mission."

Sneaky.

https://openai.com/blog/openai-lp/

/r/MachineLearning
https://redd.it/azvbmn
Question about front-end/back-end interaction: when user clicks on data X, how can I memorize X to re-use in another part of my template?

Hi guys,

I'm sure what I need help with is something very simple to most of you, but I'm relatively new to back-end programming and can't really figure this out.

So I'm building an app that collects information about academic publications. I'm using Django for the back-end and jQuery for the front end.

In my models, among other things, I have a Publication class that has a M2M relationship with an Author class. Each publication includes citations from other publications, therefore the Publication class has another M2M relationship, this time a *recursive* one, that goes through a CitationMetadata class. It looks like this:

class Publication(models.Model):
author = models.ManyToManyField('Author', through='PublicationAuthor', related_name='publications')
title = models.CharField(max_length=200)
year = models.IntegerField()
abstract = models.TextField()
citation = models.ManyToManyField('self', through='CitationMetadata', through_fields=('citer_pub', 'cited_pub'), symmetrical=False, related_name='citations')

class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)

class PublicationAuthor(models.Model):
author = models.ForeignKey('Author', related_name='publication_authors', on_delete=models.CASCADE)
publication = models.ForeignKey('Publication', related_name='publication_authors', on_delete=models.CASCADE)
author_rank = models.IntegerField()



/r/django
https://redd.it/azwwxn
Has anyone used Django + NodeJS together?

I have a long history of using django for everything. It's fantastic for so many things. But it utterly falls down once you get into responsiveness and websockets. Sorry channels, I've used you, but you just don't compare to NodeJS.

​

I am curious if anyone has attempted to use django over a DB for the things its good at, while also using Node over the same DB for the things its good at?

​

Which makes me think that the biggest problem is; has anyone had success auth'ing/passing tokens/something with node against django's auth system?

/r/django
https://redd.it/azzltx
Learning Django Repository

I have started a repository for anybody interested in learning Django. It will be an open source project where you can just fork the repository and make changes. The goal is to make a clone of Reddit, simply for learning purposes, and you can make any changes you want, then initiate a pull request.

[https://github.com/codexplore-io/django-learning-reddit-clone](https://github.com/codexplore-io/django-learning-reddit-clone)

/r/django
https://redd.it/azzla6
Help trying to understand nested serializers

I've started to mess around with Django Rest Framework, and its amazing. However, I'm overwhelmed at the same time as to how many options there are (generics, viewsets, different ways to handle nested relationships, etc.) I thought of a good exercise for my self, but am not sure the best way to set up the views and serializers (use generics, viewsets, or customizing?)
I have three models, Trainer, Team, and Pokemon.
Trainer can have many teams, so one to many, and I suppose team and pokemon could be many to many, but for the sake of simplicity, let's go with one to many as well.

I've read the documentation, so I'm not asking for a handout, but just advice on how more seasoned developers would set this up for crud operations (not sure how to save nested relations) and how best to retrieve them (say I want to show a trainers info, all their teams, and if desired, all pokemon in any given team.)

I know this is a lot too ask but I am just overwhelmed by the documentation. Thanks in advance!

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