Skip to content
Advertisement

Tag: django

How can I translate SQL query to to django ORM

I’m working on making some data consults in Django but I don’t understand quite well its ORM system yet. I need to get the transactions’ quantity for a particularly transaction’s projections. To put it briefly, I want to translate this SQL query to Python/Django syntax: These are the models involved: Answer You do this with an [.annotate(…) clause [Django-doc]]: The

ValueError could not convert string to float: ”

I’m having my app on heroku. I use timeme js to record user’s active time spend on the page, and use a hidden form to store the value into the database. Additionally, I’m using otree package to write my app. The following is the code I use: models.py views.py/pages.py in otree html The error Is it because active_duration is empty?

uwsgi can’t be installed

I’m stuck trying to install uWSGI to deploy my Django application using pip install uwsgi, but encounter this error: I’ve found several answers that unfortunately didn’t work for me, like update dev tool ,install cywin or modify uwsgiconfig.py (which doesn’t exist since it’s not installed ), or maybe I’m missing something. Answer For the install cygwin attempt, did you also

Django Exif Data: ‘IFDRational’ object is not subscriptable

I got an issue with the code: ‘IFDRational’ object is not subscriptable Here is the trace: the is issue is: Variable Value dms (45.0, 46.0, 34.29) ref ‘N’ That what I get from an image for instance. I think the code assimilate GPSLatitudeRef to degrees = dms[0][0] / dms[0][1]. The thing is GPSLatitudeRef is a letter none a number. Answer

module ‘qrcode’ has no attribute ‘make’

While integrating python library qrcode==6.1 with django==3.1.2. I have been trying to generate a qrcode which will contain the URL links for my other websites. Models.py But It always display an error saying that module ‘qrcode’ doesnot contain any attribute named ‘make()’. I want to know how to resolve this? Answer Make sure there are not any files named qrcode.py

Difference between the __lte and __gte in Django

I am trying to figure out the difference between the __lte and __gte in Django. The reason being that I am trying to create a function with dates that can work only with a time frame, so I’ve been researching between Field Lookups Comparison. I’ve looked up several documentations https://docs.djangoproject.com/en/3.0/ref/models/querysets/#exclude but didn’t reach a conclusive answer. Edited: I learned that

Use a decorator to add in a variable to request

I know the suggested way to do this is middleware, but I’d like to implement the following to add in an api_env variable, accessed at run-time, so that my view can access it: And the decorator: What’s the best way to do this? I have about 100 functions to wrap so I don’t want to add in a new parameter

Advertisement