Django Values queryset returns table id instead of the actual text in template
Hope everyone is doing great,
I have a queryset :
price = Price.objects.values('part', 'seller').annotate(latest_report=Max('added'))
returned values :
<QuerySet {'part': 1, 'seller': 1, 'latest_report': datetime.datetime(2023, 1, 12, 17, 47, 29, 645857, tzinfo=datetime.timezone.utc)}, {'part': 1, 'seller': 2, 'l
atest_report': datetime.datetime(2023, 1, 12, 16, 57, 48, 598057, tzinfo=datetime.timezone.utc)}, {'part': 1, 'seller': 3, 'latest_report': datetime.datetime(2023,
1, 12, 16, 55, 54, 662815, tzinfo=datetime.timezone.utc)}, {'part': 1, 'seller': 4, 'latest_report': datetime.datetime(2023, 1, 12, 17, 46, 36, 110057, tzinfo=dat
etime.timezone.utc)}, {'part': 2, 'seller': 1, 'latest_report': datetime.datetime(2023, 1, 11, 20, 2, 2, 336492, tzinfo=datetime.timezone.utc)}, {'part': 2, 'selle
r': 2, 'latest_report': datetime.datetime(2023, 1, 11, 20, 2, 7, 701336, tzinfo=datetime.timezone.utc)}, {'part': 2, 'seller': 3, 'latest_report': datetime.datetim
e(2023, 1, 11, 20, 2, 12, 618087, tzinfo=datetime.timezone.utc)}, {'part': 2, 'seller': 4, 'latest_report': datetime.datetime(2023, 1, 11, 20, 2, 17, 900953, tzinf
o=datetime.timezone.utc)}>
I want to display part name "text" and part seller "text" in template, i tried :
{% for item in price %}
/r/django
https://redd.it/10afetm
Hope everyone is doing great,
I have a queryset :
price = Price.objects.values('part', 'seller').annotate(latest_report=Max('added'))
returned values :
<QuerySet {'part': 1, 'seller': 1, 'latest_report': datetime.datetime(2023, 1, 12, 17, 47, 29, 645857, tzinfo=datetime.timezone.utc)}, {'part': 1, 'seller': 2, 'l
atest_report': datetime.datetime(2023, 1, 12, 16, 57, 48, 598057, tzinfo=datetime.timezone.utc)}, {'part': 1, 'seller': 3, 'latest_report': datetime.datetime(2023,
1, 12, 16, 55, 54, 662815, tzinfo=datetime.timezone.utc)}, {'part': 1, 'seller': 4, 'latest_report': datetime.datetime(2023, 1, 12, 17, 46, 36, 110057, tzinfo=dat
etime.timezone.utc)}, {'part': 2, 'seller': 1, 'latest_report': datetime.datetime(2023, 1, 11, 20, 2, 2, 336492, tzinfo=datetime.timezone.utc)}, {'part': 2, 'selle
r': 2, 'latest_report': datetime.datetime(2023, 1, 11, 20, 2, 7, 701336, tzinfo=datetime.timezone.utc)}, {'part': 2, 'seller': 3, 'latest_report': datetime.datetim
e(2023, 1, 11, 20, 2, 12, 618087, tzinfo=datetime.timezone.utc)}, {'part': 2, 'seller': 4, 'latest_report': datetime.datetime(2023, 1, 11, 20, 2, 17, 900953, tzinf
o=datetime.timezone.utc)}>
I want to display part name "text" and part seller "text" in template, i tried :
{% for item in price %}
/r/django
https://redd.it/10afetm
reddit
Django Values queryset returns table id instead of the actual text...
Hope everyone is doing great, I have a queryset : price = Price.objects.values('part', 'seller').annotate(latest\_report=Max('added')) returned...
How do you delete expired sessions?
I have a hosted django app and found out there are some old expired sessions as old as 2018.
Is it a good practice to delete expired sessions?
What is the usual strategy to delete expired sessions?
May be a CRON job, or run the "clearsessions" management command for every deployment, etc...?
Any there any problems/pitfalls with deleting expired sessions?
/r/django
https://redd.it/10anmjw
I have a hosted django app and found out there are some old expired sessions as old as 2018.
Is it a good practice to delete expired sessions?
What is the usual strategy to delete expired sessions?
May be a CRON job, or run the "clearsessions" management command for every deployment, etc...?
Any there any problems/pitfalls with deleting expired sessions?
/r/django
https://redd.it/10anmjw
reddit
How do you delete expired sessions?
I have a hosted django app and found out there are some old expired sessions as old as 2018. Is it a good practice to delete expired...
Unique field not throwing graceful ValidationError
Creating API app. Field in question:
phone = models.CharField(max_length=20, null=True, unique=True, error_messages={"unique": "A user with that phone number already exists, please login."})
I ran the migration and its clearly being enforced when I try to create a user with the same phone, but why not gracefully (see below) like email does?
OUTPUT
API: 422 output to API but no error message
Server log: [Long stack trace\] django.db.utils.IntegrityError: duplicate key value violates unique constraint + INTERNAL SERVER ERROR given
Thanks!
/r/django
https://redd.it/109zzk1
Creating API app. Field in question:
phone = models.CharField(max_length=20, null=True, unique=True, error_messages={"unique": "A user with that phone number already exists, please login."})
I ran the migration and its clearly being enforced when I try to create a user with the same phone, but why not gracefully (see below) like email does?
OUTPUT
API: 422 output to API but no error message
Server log: [Long stack trace\] django.db.utils.IntegrityError: duplicate key value violates unique constraint + INTERNAL SERVER ERROR given
Thanks!
/r/django
https://redd.it/109zzk1
reddit
Unique field not throwing graceful ValidationError
Creating API app. Field in question: phone = models.CharField(max\_length=20, null=*True*, unique=*True*, error\_messages={"unique": "A user with...
How could we do a reliable social authentication api with custom user model?
I've been wanting to make a vue/ionic mobile app with django as the backend and I wanted to make 3 sign in options (google, facebook, email).
I have implemented the email sign up/log in api with simpleJWT. I then tried to use
I found the
is there a way to either fix this issue or maybe there's a different implementation I should do?
also how can I register custom users while using social auth? registering accounts with socialaccounts fills the user form automatically and I want to ask the user to add certain fields like gender and birthday etc.
any sort of help or sources or demos would be appreciated.
/r/django
https://redd.it/10aqfic
I've been wanting to make a vue/ionic mobile app with django as the backend and I wanted to make 3 sign in options (google, facebook, email).
I have implemented the email sign up/log in api with simpleJWT. I then tried to use
django-allauth to make the facebook and google auth but I discovered that they have their own views and not very good documentation for customizing the views.I found the
dj-rest-auth as a method of making a rest auth api, unfortunately when using the documentation I have this error coming up. is there a way to either fix this issue or maybe there's a different implementation I should do?
also how can I register custom users while using social auth? registering accounts with socialaccounts fills the user form automatically and I want to ask the user to add certain fields like gender and birthday etc.
any sort of help or sources or demos would be appreciated.
/r/django
https://redd.it/10aqfic
GitHub
Update 2.2.6 broke Google login · Issue #465 · iMerica/dj-rest-auth
Trace : site-packages/dj_rest_auth/registration/serializers.py, line 150, in validate -> login = self.get_social_login(adapter, app, social_token, token) site-packages/dj_rest_auth/registrat...
how to do ip tests locally
hello everyone, i'm studying django and i came across an exercise where it asks to send an alert message in case the user ip is different from the previous one. is there any way to test this? being in local i always get '127.0.0.1' back
/r/django
https://redd.it/109w89y
hello everyone, i'm studying django and i came across an exercise where it asks to send an alert message in case the user ip is different from the previous one. is there any way to test this? being in local i always get '127.0.0.1' back
/r/django
https://redd.it/109w89y
reddit
how to do ip tests locally
hello everyone, i'm studying django and i came across an exercise where it asks to send an alert message in case the user ip is different from the...
Extracting pdf page count corrupts attachment
I am developing a Django website, wherein I have a django form that collects some data and a file from the user, and then mail the response to a mail ID. If the file happens to be a PDF, the form is supposed to automatically get its page count and add it to the mail body.
I am able to successfully isolate pdf files and even get the page count value correctly, the process of getting page count seems to corrupt the pdf file when it is attached to the email.
Emailing is being handled with django email, and I have tried to read page count using PyPDF2 and pdfminer, but both give the same outcome. The file is not being stored to any database.
What should I do?
EDIT: Problem solved. Thanks all!
/r/django
https://redd.it/109nitk
I am developing a Django website, wherein I have a django form that collects some data and a file from the user, and then mail the response to a mail ID. If the file happens to be a PDF, the form is supposed to automatically get its page count and add it to the mail body.
I am able to successfully isolate pdf files and even get the page count value correctly, the process of getting page count seems to corrupt the pdf file when it is attached to the email.
Emailing is being handled with django email, and I have tried to read page count using PyPDF2 and pdfminer, but both give the same outcome. The file is not being stored to any database.
What should I do?
EDIT: Problem solved. Thanks all!
/r/django
https://redd.it/109nitk
reddit
Extracting pdf page count corrupts attachment
I am developing a Django website, wherein I have a django form that collects some data and a file from the user, and then mail the response to a...
Django amp
Please have any one successfully implemented django amp in his/her site. I tried using django amp according to this documentation https://pypi.org/project/django-amp-tools/ but i'm having errors which says TEMPLATES = django_settings.TEMPLATES[0]['OPTIONS']['loaders']
KeyError: 'loaders'.
Please how can I solve this problem
/r/django
https://redd.it/109kv9h
Please have any one successfully implemented django amp in his/her site. I tried using django amp according to this documentation https://pypi.org/project/django-amp-tools/ but i'm having errors which says TEMPLATES = django_settings.TEMPLATES[0]['OPTIONS']['loaders']
KeyError: 'loaders'.
Please how can I solve this problem
/r/django
https://redd.it/109kv9h
PyPI
django-amp-tools
Accelerated mobile pages (AMP) in django.
tempy: render beautiful weather data to your terminal
I'd love to hear feedback from anyone who's interested.
https://github.com/noprobelm/tempy
/r/Python
https://redd.it/10b289u
tempy is a small Python project I've been working on. It uses rich to render data from WeatherAPI to your terminal.I'd love to hear feedback from anyone who's interested.
https://github.com/noprobelm/tempy
/r/Python
https://redd.it/10b289u
GitHub
GitHub - noprobelm/tempy: A simple, visually pleasing weather report in your terminal.
A simple, visually pleasing weather report in your terminal. - noprobelm/tempy
Researchers from Meta AI released ‘balance,’ a Python Package for Balancing Biased Data Samples
https://www.marktechpost.com/2023/01/13/researchers-from-meta-ai-released-balance-a-python-package-for-balancing-biased-data-samples/
/r/Python
https://redd.it/10b1d3i
https://www.marktechpost.com/2023/01/13/researchers-from-meta-ai-released-balance-a-python-package-for-balancing-biased-data-samples/
/r/Python
https://redd.it/10b1d3i
MarkTechPost
Researchers from Meta AI released 'balance,' a Python Package for Balancing Biased Data Samples
Artificial intelligence and machine learning are now essential components in various tasks that contribute to a company's growth, such as marketing, thanks largely to recent technological advancements in these fields. However, AI has its own set of challenges.…
GitHub - 0ut0flin3/openai-davinci003-python-speech: A Python script to use OpenAI's text-davinci-003 model using your own voice instead of text, in any language
https://github.com/0ut0flin3/openai-davinci003-python-speech
/r/Python
https://redd.it/10apqt2
https://github.com/0ut0flin3/openai-davinci003-python-speech
/r/Python
https://redd.it/10apqt2
GitHub
GitHub - 0ut0flin3/openai-davinci003-python-speech: A Python script to use OpenAI's text-davinci-003 model using your own voice…
A Python script to use OpenAI's text-davinci-003 model using your own voice instead of text, in any language - GitHub - 0ut0flin3/openai-davinci003-python-speech: A Python script to use Ope...
10 Tips to Optimize PostgreSQL Queries in Django - w/ Jupyter notebook
Hi there! Those working with big RDBS might be interested in this new entry on optimizing Django and SQL queries. There is also a jupyter notebook to test the tips linked in the article.
Enjoy!
https://blog.gitguardian.com/10-tips-to-optimize-postgresql-queries-in-your-django-project/
/r/Python
https://redd.it/10av799
Hi there! Those working with big RDBS might be interested in this new entry on optimizing Django and SQL queries. There is also a jupyter notebook to test the tips linked in the article.
Enjoy!
https://blog.gitguardian.com/10-tips-to-optimize-postgresql-queries-in-your-django-project/
/r/Python
https://redd.it/10av799
GitGuardian Blog - Take Control of Your Secrets Security
10 Tips to Optimize PostgreSQL Queries in Your Django Project
Philippe is back, this time joined by Laurent, to reveal their best tips & tricks to make Django and Postgres the best friends in the world.
I made Light Config (LCO) - a super small package/snippet to load a config once and use it anywhere in your application
Light Config (LCO)
I made this package for prototypes, MVPs or research code, not really something I would use for production. I find it neat since you can just load a config like so from anywhere in your code.
import lco
lco.init("yourconfigfile.yml")
And access the configuration parameters specified in the YAML file from anywhere (across threads and processes) like so:
import lco
lco"some_key"
lco"some_group""some_key"
I hope this is useful for anyone besides me :)
Edit:
If you don't have tons of nested parameters and different data types I would recommend using dotenv over my solution!
/r/Python
https://redd.it/10axlc6
Light Config (LCO)
I made this package for prototypes, MVPs or research code, not really something I would use for production. I find it neat since you can just load a config like so from anywhere in your code.
import lco
lco.init("yourconfigfile.yml")
And access the configuration parameters specified in the YAML file from anywhere (across threads and processes) like so:
import lco
lco"some_key"
lco"some_group""some_key"
I hope this is useful for anyone besides me :)
Edit:
If you don't have tons of nested parameters and different data types I would recommend using dotenv over my solution!
/r/Python
https://redd.it/10axlc6
GitHub
GitHub - MiniXC/lco: Light Config for research code, MVPs and prototypes.
Light Config for research code, MVPs and prototypes. - GitHub - MiniXC/lco: Light Config for research code, MVPs and prototypes.
Python bindings for RocksDB and LevelDB
My team and I have been working on a large project to unify interfaces across the most famous Key-Value Stores and extend their functionality to support Documents, Graphs, and other forms of content. Similar to how RedisJSON, RedisGraph, and RediSearch augment the functionality of Redis.
import ukv.rocksdb as embedded
db = embedded.DataBase('/tmp/ukv/rocksdb/')
db.main[42] = 'Hi'
Python is the most critical language for the bindings, as we do a fair share of Machine Learning. We are building the bindings for Graph collections to look like NetworkX and the ones for Tabular collections - like Pandas. But the latter is still far from being feature-complete.
db['social'].graph.add_edge(alice_id, bob_id)
db['payments'].table[['name', 'amount']].tail(5)
There is also little difference between having it locally vs. remotely. You can set up a remote machine with 100 TBs of NVMe SSDs, running RocksDB, storing a graph with 1 Trillion edges, and still talk to it as if it is a tiny local in-memory graph.
The project is still in its infancy, and we would appreciate any feedback! Thank you!
[GitHub](https://github.com/unum-cloud/ukv)
[Documentation](https://unum.cloud/ukv)
/r/Python
https://redd.it/10b4n3v
My team and I have been working on a large project to unify interfaces across the most famous Key-Value Stores and extend their functionality to support Documents, Graphs, and other forms of content. Similar to how RedisJSON, RedisGraph, and RediSearch augment the functionality of Redis.
import ukv.rocksdb as embedded
db = embedded.DataBase('/tmp/ukv/rocksdb/')
db.main[42] = 'Hi'
Python is the most critical language for the bindings, as we do a fair share of Machine Learning. We are building the bindings for Graph collections to look like NetworkX and the ones for Tabular collections - like Pandas. But the latter is still far from being feature-complete.
db['social'].graph.add_edge(alice_id, bob_id)
db['payments'].table[['name', 'amount']].tail(5)
There is also little difference between having it locally vs. remotely. You can set up a remote machine with 100 TBs of NVMe SSDs, running RocksDB, storing a graph with 1 Trillion edges, and still talk to it as if it is a tiny local in-memory graph.
The project is still in its infancy, and we would appreciate any feedback! Thank you!
[GitHub](https://github.com/unum-cloud/ukv)
[Documentation](https://unum.cloud/ukv)
/r/Python
https://redd.it/10b4n3v
GitHub
GitHub - unum-cloud/ustore: Multi-Modal Database replacing MongoDB, Neo4J, and Elastic with 1 faster ACID solution, with NetworkX…
Multi-Modal Database replacing MongoDB, Neo4J, and Elastic with 1 faster ACID solution, with NetworkX and Pandas interfaces, and bindings for C 99, C++ 17, Python 3, Java, GoLang 🗄️ - unum-cloud/us...
Forwarded from Python Daily
How do I integrate TailwindCSS with Django? I’ve tried multiple tutorials and nothing is working.
What’s the best way to do this? Looking for a current tutorial and directions.
/r/djangolearning
https://redd.it/10baq06
What’s the best way to do this? Looking for a current tutorial and directions.
/r/djangolearning
https://redd.it/10baq06
reddit
How do I integrate TailwindCSS with Django? I’ve tried multiple...
What’s the best way to do this? Looking for a current tutorial and directions.
why SQL is a requirement for Django jobs?
I was researching job requirements for Django developers, I have conducted a study on various job listings and have noticed that a significant number of companies require knowledge of raw SQL as a skill. However, I am puzzled by this requirement as I understand that Django follows the MVT (Model View Template) pattern, where database-related code is handled by the Model. This raises a question as to why raw SQL skills would be necessary for a Django developer. Can you provide a detailed explanation on the importance of raw SQL skills in the context of Django development and how it relates to the MVT pattern? Are there any specific tasks or scenarios that would require the use of raw SQL in a Django project? Are there any particular industry segments or areas where this skill is particularly valued?
/r/djangolearning
https://redd.it/10b3ls8
I was researching job requirements for Django developers, I have conducted a study on various job listings and have noticed that a significant number of companies require knowledge of raw SQL as a skill. However, I am puzzled by this requirement as I understand that Django follows the MVT (Model View Template) pattern, where database-related code is handled by the Model. This raises a question as to why raw SQL skills would be necessary for a Django developer. Can you provide a detailed explanation on the importance of raw SQL skills in the context of Django development and how it relates to the MVT pattern? Are there any specific tasks or scenarios that would require the use of raw SQL in a Django project? Are there any particular industry segments or areas where this skill is particularly valued?
/r/djangolearning
https://redd.it/10b3ls8
reddit
why SQL is a requirement for Django jobs?
I was researching job requirements for Django developers, I have conducted a study on various job listings and have noticed that a significant...
A tutorial for class based views user registration with email verification?
/r/djangolearning
https://redd.it/10avzs0
/r/djangolearning
https://redd.it/10avzs0
reddit
A tutorial for class based views user registration with email...
Posted in r/djangolearning by u/KhZaym • 1 point and 1 comment
Is it right to create a custom authentication form.Forms instead of extending the Django AuthenticationForm?
I've been working on my first authentication system using Django and I wanted to make it complete, with field validations, login with email and even send a confirmation email to activate the account (which I haven't done yet). So far, I have made: A small custom user model with email field, an extension of the UserCreationForm to register users using their emails (which works), and finally the main problem, I tried to make an extension of the AuthenticationForm to login users using their emails instead of their usernames, but it doesn't seem to work. First, I tried to overwrite the clean method of the form but it didn't work, then I tried to make a backend.py to overwrite how the authentication system works but it failed and I couldn't understand why, so I created my own form using form.Forms with all the necessary fields and validations and it worked fine. I've heard that it's not a good idea to use form.Forms if I interact with models, but it was the only solution I could think of. Should I try to extend the AuthenticationForm instead of creating a form from scratch? Or is my form fine for the system I want
/r/djangolearning
https://redd.it/10a43cg
I've been working on my first authentication system using Django and I wanted to make it complete, with field validations, login with email and even send a confirmation email to activate the account (which I haven't done yet). So far, I have made: A small custom user model with email field, an extension of the UserCreationForm to register users using their emails (which works), and finally the main problem, I tried to make an extension of the AuthenticationForm to login users using their emails instead of their usernames, but it doesn't seem to work. First, I tried to overwrite the clean method of the form but it didn't work, then I tried to make a backend.py to overwrite how the authentication system works but it failed and I couldn't understand why, so I created my own form using form.Forms with all the necessary fields and validations and it worked fine. I've heard that it's not a good idea to use form.Forms if I interact with models, but it was the only solution I could think of. Should I try to extend the AuthenticationForm instead of creating a form from scratch? Or is my form fine for the system I want
/r/djangolearning
https://redd.it/10a43cg
reddit
Is it right to create a custom authentication form.Forms instead...
I've been working on my first authentication system using Django and I wanted to make it complete, with field validations, login with email and...
10 Tips to Optimize PostgreSQL Queries in Your Django Project
Hi there! Those working with big RDBS might be interested in this new entry on optimizing Django and SQL queries. There is also a jupyter notebook to test the tips linked in the article.
Enjoy!
​
https://blog.gitguardian.com/10-tips-to-optimize-postgresql-queries-in-your-django-project/
/r/django
https://redd.it/10av4y9
Hi there! Those working with big RDBS might be interested in this new entry on optimizing Django and SQL queries. There is also a jupyter notebook to test the tips linked in the article.
Enjoy!
​
https://blog.gitguardian.com/10-tips-to-optimize-postgresql-queries-in-your-django-project/
/r/django
https://redd.it/10av4y9
GitGuardian Blog - Take Control of Your Secrets Security
10 Tips to Optimize PostgreSQL Queries in Your Django Project
Philippe is back, this time joined by Laurent, to reveal their best tips & tricks to make Django and Postgres the best friends in the world.
Need help finding django projects that use asgi
Hi guys , can you please suggest any mature/working projects that use asgi for my reference/learning ? I kinda am stuck trying to decide whether I have to port my work project to asgi from wsgi once we migrate from 2.2 to 3.2. any help is appreciated. Thanks.
/r/django
https://redd.it/10bdnac
Hi guys , can you please suggest any mature/working projects that use asgi for my reference/learning ? I kinda am stuck trying to decide whether I have to port my work project to asgi from wsgi once we migrate from 2.2 to 3.2. any help is appreciated. Thanks.
/r/django
https://redd.it/10bdnac
reddit
Need help finding django projects that use asgi
Hi guys , can you please suggest any mature/working projects that use asgi for my reference/learning ? I kinda am stuck trying to decide whether I...
Exciting news! I have just released a new tutorial series on Youtube, where I walk through the process of building a CV scanning and job-matching web application using Django. In this first tutorial, we will be giving an overview of the project and discussing the main features, functionality,
https://youtube.com/watch?v=ZcY9EILTpYM&feature=share
/r/django
https://redd.it/10bhptt
https://youtube.com/watch?v=ZcY9EILTpYM&feature=share
/r/django
https://redd.it/10bhptt
YouTube
00 Building a CV Scanning and Job Matching Web App with Django Overview Tutorial
In this tutorial, we will be giving an overview of the Django project we built for scanning CVs and matching them with job description keywords. We will be discussing the project's main features, functionality, and the technologies used to build it. By the…