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
Tag: django
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
DRF add non model fields just to update or create model instance
I have this issue at the moment with DRF. I’m recieving extra fields that the model is not using. But those values will define the fields within the model. And i got this model All I need is to parse file_name and file_type to upload img to create a url_img and upload it on cloud. Is there a way to
How to order queryset based on best match in django-rest-framework?
I am trying to order results of a query with parameters by number of matches. For example, let’s say we have a Model: With a Serializer: And a ViewSet: What I need to do is count every match the filter finds and then order the queryset by that number of matches for each template. For example: I want to find
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
Django, link a model field with an admin model field with ForeignKey
I’m trying to link a “normal” model field with an admin model field, for example I have a table “Post” and I want to add the admin username as a ForeignKey to the field “Author” of the table Post. I mean : Where admin.username refers the username of auth_user admin model Thanks for your help Answer As the referencing the