Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Is nginx required to deploy a gatsby front end beside a django REST backend?
I'm currently trying to deploy a Django REST backend and a React/Gatsby frontend to Heroku (using the steps outlined in this article https://dev.to/mdrhmn/deploying-react-django-app-using-heroku-2gfa), and I'm having some issues sending requests from the front end to the back end. GET Instruction useEffect(() => { fetch('http://127.0.0.1:8000/ljwe/symbol/?freq=monthly&symbol_id=1') .then(res => res.json()) .then(data => setOptions(data)) .catch((err) => {console.error(err)}) }, []); CORS_ALLOW_ALL_ORIGINS = True in settings.py "proxy": "http://localhost:8000" in both gatsby-config.js and package.json files Locally, everything works fine and the database is successfully queried, returning the proper information Unfortunately, when I push my changes to Heroku, the data is no longer displayed. I'm using the following build packs: heroku/node.js https://github.com/heroku/heroku-buildpack-static heroku/python When I run heroku run psql <heroku_app> I can query the app's database and see relevant entries in the tables. In addition, when I manually enter my API endpoints on the Heroku-hosted version, they work as intended. My Heroku logs also seem to show the request going through fine. Browser Console Output -
How i transfer data(variables) from one html page to another page, here i am using html & django framework
here in my code i am displaying elements from a database using a loop at the the user click buy button, i want to pass the particular product id to another page. how i get the product id & how it passed to another page... HTML page {% for product in products %} <div class="col-md-3"> <div class="card"> <img src="{{product.product_image}}" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">{{product.product_name}}</h5> <p class="card-text">₹{{product.product_price}}</p> <a href="{% url 'buy' %}" class="btn btn-primary"> Buy</a> </div> </div> </div> {% endfor %} -
Connection refused when accessing Nginx container from React container
I'm trying to run the Django-React application inside the docker, when I start testing the React application, this error appears. FetchError: request to http://localhost/media/filer_public/03/58/0358cfac-1ac5-4caa-8b6b-bd20361dd878/import_filesa0a0b76730363b11ebb8a73cf86249c70c_b167f69b364a11ebb8a73cf86249c70c.jpg failed, reason: connect ECONNREFUSED 127.0.0.1:80 Pay attention to _next As I understand it, there is a request for localhost:80 inside the React container, but since there is no such address in this container, this exception is raised. Images that are just a request to localhost:80/media/filer.../ receive a response. Example of an image request that works <img src="http://localhost/media/filer_public/03/58/0358cfac-1ac5-4caa-8b6b-bd20361dd878/import_filesa0a0b76730363b11ebb8a73cf86249c70c_b167f69b364a11ebb8a73cf86249c70c.jpg" /> At the moment I am passing the api address in a similar way via .env file BACKEND_ADDRESS=localhost:80 Is it possible to pass the address of the Nginx container to the React container? Or are there any other ways to solve the problem? docker-compose.yml version: "3.8" services: nginx: restart: unless-stopped build: context: . dockerfile: ./nginx/Dockerfile ports: - 80:80 volumes: - media:/code/media/ - static:/code/staticfiles/ - ./nginx/conf:/etc/nginx/conf.d depends_on: - app networks: - backend db: image: postgres:latest volumes: - db-data:/var/lib/postgresql/data environment: - POSTGRES_DB=postgres - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres networks: - backend app: container_name: django_app build: . command: gunicorn project.wsgi:application --bind 0.0.0.0:8000 --reload --workers=4 --threads=4 --access-logfile - ports: - 8000:8000 volumes: - .:/code - media:/code/media/ - static:/code/staticfiles/ depends_on: - db networks: - backend redis: … -
Why isn't Django Rest Framework Token Authentication working?
I am currently using Django rest framework and trying to implement a Token Authentication system. Currently, my settings.py looks like this: REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.TokenAuthentication' ] } and rest_framework.authtoken is in installed_apps. My urls.py looks like this: urlpatterns = [ ... url('^v1/users/$', views.users_view), ... ] My views.py looks like this: @authentication_classes((TokenAuthentication,)) @api_view(['PUT', 'POST']) def users_view(request): ... I'm working in postman to test the API and regardless of whether I put the token in the Bearer Token authorization field, the API works as intended. What do I need to change for the token authentication to work as intended? -
query set too many objects to unpack expected(2) in django templateView
I have written a view to show open,completed,accepted and closed tickets on dashboard on clicking which goes into particular url to display the tickets accordingly and am switching the templates according to their status,I am quering the ticket status and i get the following error too many objects to unpack (expected 2) models.py class Ticket(models.Model): ticket_title = models.CharField(max_length=200) ticket_description = models.TextField() created_by = models.ForeignKey(User,related_name = 'created_by',blank=True,null=True,on_delete=models.CASCADE) STATUS_CHOICES = ( ('Opened','Opened'), ('Accepted','Accepted'), ('Completed','Completed'), ('Closed','Closed') ) status = models.CharField('Status',choices=STATUS_CHOICES,max_length = 100,default = 'Opened') closed_date = models.DateTimeField(blank=True,null=True) completed_date = models.DateTimeField(blank=True,null=True) accepted_date = models.DateTimeField(blank=True,null=True) opened_date = models.DateTimeField(blank=True,null=True) accepted_by = models.ForeignKey(User,related_name='assigned_to',on_delete=models.CASCADE,blank=True,null=True) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) def __str__(self): return self.ticket_title Views.py class DeveloperTicketView(TemplateView): def get_template_names(self): ticket_type = Ticket.objects.filter('status') if ticket_type == "Opened": template_name = 'app/open_tickets.html' elif ticket_type == 'Accepted': template_name = 'app/dev_accepted_ticket.html' elif ticket_type == 'Completed': template_name = 'app/dev_completed_tickets.html' else: template_name = 'app/dev_closed_tickets.html' return template_name def get_context_data(self, **kwargs): context = super(TemplateView,self).get_context_data(**kwargs) context['open_tickets'] = Ticket.objects.filter(status = 'Opened') context['accepted_tickets'] = Ticket.objects.filter(status = 'Accepted',accepted_by = self.request.user) context['completed_tickets'] = Ticket.objects.filter(status = 'Completed',accepted_by = self.request.user) context['closed_tickets'] = Ticket.objects.filter(status = 'Closed',accepted_by = self.request.user) return context -
Django - Can't read media files
I'm using Django to create a website where you can upload an image on that website and check if the image contains Moire pattern. Here is the project structure: In file settings.py, I specified the following directory for media files: MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' and in file views.py, I implemented the API that will receive the image and detect moire pattern like this: from django.core.files.storage import default_storage def index(request): if request.method == 'POST': f = request.FILES['sentFile'] response = {} fname = 'pic.jpg' fname2 = default_storage.save(fname, f) file_url = default_storage.url(fname2) image = Image.open(file_url) pred_label = moire_detect(image) response['label'] = pred_label return render(request, 'frontpage.html', response) else: return render(request, 'frontpage.html') However, when I try to open the image using Image module of Pillow, I got this error "No such file or directory: '/media/pic_O1TOyCK.jpg'". I don't really understand what is happening here, because the path is correct. Any help would be really appreciated. -
Add total pages to the Django Rest Framework response when using pagination
At the Django Rest Framework Documentation you can add pagination according to the document at this link: https://www.django-rest-framework.org/api-guide/pagination/#modifying-the-pagination-style class StandardResultsSetPagination(PageNumberPagination): page_size = 100 page_size_query_param = 'page_size' max_page_size = 1000 and the response will look like: HTTP 200 OK { "count": 1023 "next": "https://api.example.org/accounts/?page=5", "previous": "https://api.example.org/accounts/?page=3", "results": [ … ] } How can I add "total_pages" to the response? HTTP 200 OK { "count": 1023 ==>"total_pages": 12 "next": "https://api.example.org/accounts/?page=5", "previous": "https://api.example.org/accounts/?page=3", "results": [ … ] } I looked into the DRF code and saw the PageNumberPagination class has a "num_pages" property. But I'm not sure how to call it in the StandardResultsSetPagination class. https://github.com/encode/django-rest-framework/blob/0323d6f8955f987771269506ca5da461e2e7a248/rest_framework/pagination.py -
Passing json data to django template and then to chartjs
I have two problems here. problem 1: I was trying to get my data converted to JSON and then pass it to a django template.But somehow it throws "Uncaught SyntaxError: Unexpected token '&'" when i checked in the console. However the data when put in between {{}} in django html template renders properly. Then found out my JSON data came with replaced all the quotes with & quot;. Why is this happening? How to solve this? views.py def tweetCount(request): tweetCount = api2.get_recent_tweets_count(query) tweetData = [] for tweet in tweetCount.data: obj = {} obj['end'] = tweet['end'] obj['count'] = tweet['tweet_count'] tweetData.append(obj) tweetData = json.dumps(tweetData) return render(request, 'tweetCount.html', {'tweetData' : tweetData}) tweetCount.html {% extends 'main.html' %} {% block content %} <p>{{ tweetData }}</p> <div id="container" style="width: 75%"> <canvas id="chart"></canvas> </div> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script> var data = {{tweetData}} console.log(data) </script> {% endblock %} problem 2 : How do I use this data in chartjs ? I want a Time scale graph. Someone please help me with this. -
Django API ServerError 500 ChunkedEncodingError IncompleteRead
I made an API Server using Django restframework. And Android Client will use it. When I request POST in webpage, it works without any problem. But in android, It raise 500 internal server error.. I don't know the reasons. Then I try to request using httpie on django terminal. It raised 500 Internal ServerError and ChunkedEncodingError. (venv) C:\github\dj-postgres-heroku>http --json -v POST asap-ds.herokuapp.com/users/profiles nickname="키위" introductin="http응답확인" jobs=null related_user={"phone_nm"="01044447777", "login_ID"="Qkrgydnjs99", "age"=20,"gender"=0,"password"="Qkrgydnjs99"} POST /users/profiles HTTP/1.1 Accept: application/json, */*;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Content-Length: 206 Content-Type: application/json Host: asap-ds.herokuapp.com User-Agent: HTTPie/2.6.0 { "age": "20,gender=0,password=Qkrgydnjs99}", "introduction": "http응답확인", "jobs": "null", "login_ID": "Qkrgydnjs99,", "nickname": "키위", "related_user": "{phone_nm=01044447777," } HTTP/1.1 500 Internal Server Error Connection: keep-alive Content-Type: text/html Date: Tue, 23 Nov 2021 03:38:37 GMT Referrer-Policy: same-origin Server: gunicorn Transfer-Encoding: chunked Via: 1.1 vegur X-Content-Type-Options: nosniff http: error: ChunkedEncodingError: ('Connection broken: IncompleteRead(5578 bytes read, 4662 more expected)', IncompleteRead(5578 bytes read, 4662 more expected)) When I request on webpage, I works well. HTTP 201 Created Allow: GET, POST, HEAD, OPTIONS Content-Type: application/json Vary: Accept { "nickname": "악어", "introduction": "웹페이지에서", "jobs": null } enter image description here Please anybody help me.. -
My save() method dosen't work when user has foreignKey set to object None
I have a user update form. The user model contains a field that is a foreign key to a group object. When I want to update a user that does not have a group set (value = None) then the save() method does not get called after click "save" button. group_name = models.ForeignKey(Group, on_delete=models.CASCADE, blank=True, null=True) -
Unable to get records using Django ORM
Problem: Trying to get a record using Django ORM, from a table that contains a JSON field, I'm using the following line: test_object = House.objects.get(id=301) Error TypeError: the JSON object must be str, bytes or bytearray, not dict Possible issue Noticed that a previous developer updated the format of the JSON field in the table, seems that JSON had a bad format. Script used to format the JSON column: for i in data: jsonstring = json.dumps(i.result) new_clear = jsonstring.replace("\\", "") new_clear = jsonstring.replace("NaN", "null") i.result = json.loads(new_clear) i.save() Comments In pgAdmin the JSON field looks good and it is formatted properly, see a partial copy of the JSON below: {"owner_id": 45897, "first_name": "John", "last_name": "DNC", "estate_id": 3201, "sale_date": "3/18/19", "property_street": "123 main st", "property_city": "Miami", "property_state": "FL", "property_zipcode": 33125, "Input_First_Name": "John", "Input_Last_Name": "DNC"} I would like to know how to deal with this JSON field in order to query the object. Any help will be appreciated. Thanks. -
Celery/redis tasks don't always complete - not sure why or how to fit it
I am running celery v 4.0.3/redis v 4.09 in a django v 3.0.1 application (Python v 3.6.9). I am also using face_recognition in a celery task find_faces to find faces in the images I have uploaded to the application, among other image processing celery tasks. There are no issues processing five or fewer image files in that all the image processing celery tasks complete successfully. When I have the image process tasks (including find_faces) iterate over 100 images there are 10-30 images where the find_faces task does not complete. When I use flower v0.9.7 to take a look at the celery tasks, I see that the find_faces task status is "started" for those images that did not complete. All the other images have find_faces task status as "success". The status of these "started" tasks never changes, and there are no errors or exceptions reported. I can then run the image processing tasks, including the find_faces task, on each of these images individually, and the task status is "success". These results do not change if I run celery as a daemon or locally, or if I run the django app using wsgi and apache or runserver. Flower also reports that retries … -
How to sum annotation values by groupby in Django
In Django, an error occurs when calculating (Sum) with the value obtained by annotate rather than as a unique field of the model. Is it possible to calculate with only unique fields? I want to find Sum by groupby 'enroll_injection' value into 'student__research' . enroll_injection = test.filter(Q(student__is_deleted=0))\ .values('student')\ .annotate(injection=Max('injection_date'), enroll=Max('enroll_date'))\ .values('student__research')\ .annotate(enroll_injection=Cast(F('enroll_date'), DateField()) - Cast(F('injection_date'), DateField()))\ .values('assignment__research__research_name', 'enroll_injection')\ .order_by('assignment__research__research_name') Error: Cannot compute Sum('<CombinedExpression: Cast(F(enroll_date)) - Cast(F(injection_date))>'): '<CombinedExpression: Cast(F(enroll_date)) - Cast(F(injection_date))>' is an aggregate -
Django tests are not outputting Messages in template rendering
I can't seem to get a unit test to check if Messages are rendering properly in my template. As per my template, I'm not getting any output where the messages should be listed. I'm using pytest 6.2.5 and Django 3.1.13 if that's helpful. Here is my test code: import pytest from django.contrib import messages from django.contrib.messages.middleware import MessageMiddleware from django.contrib.sessions.middleware import SessionMiddleware from django.test import RequestFactory from django.views.generic import TemplateView pytestmark = pytest.mark.django_db class TestBaseTemplate: def test_messages_middleware(self): request = RequestFactory().get("/") view = TemplateView.as_view(template_name="base.html") middleware1 = SessionMiddleware() middleware1.process_request(request) request.session.save() middleware2 = MessageMiddleware() middleware2.process_request(request) foobar_msg = "Hello, world!" messages.info(request, foobar_msg) request.session.save() response = view(request) response.render() content = response.content.decode("utf-8") # This assert fails assert foobar_msg in content My message block in the template (base.html) is straight-forward (and does work in views that send messages): {% if messages %} <div> {% for message in messages %} <p>{{ message }}</p> {% endfor %} </div> {% endif %} I can see through debugging that before you get to rendering the response that the "Hello, world!" message is being noted properly in the request via the Session/Message middleware, it's just not being rendered in the response. Any ideas on what I'm missing? Do I need to do … -
Django 3.2 - login form on homepage
I’m fairly new to Djanjo, and I have got a simple app working, however all the tutorials I can find have a “login” link on the homepage which redirects to a login page, this seems unnecessary ( at least for what i want ), I’d prefer to have the login page on the homepage, so the user can log straight in from there. I found some very old questions on here where people asking same/similar, but the answers seem old and perhaps even overly complicated. I think what I need to do, is to somehow set my urls.cfg in config/ for ‘’ to point to the built in auth view, but I cannot find a clear example of that. I’d like to achieve it with minimal customization. Just looking for an upto date pointer in the right direction for latest Django 3 please, if anyone can help me better understand what I should do. -
creating a delay in an html render in django?
I'm making a chatbot for practice in Django. When the user sends a message, the chatbot responds a few seconds later. I can display the text of the user and chatbot be in the template below. I'm unsure of how to create this delay. I understand that using javascript we can use the timeout() function: setTimeout(() => { console.log("World!"); }, 2000); Currently this is what I have: {% extends 'chat.html' %} {% block chatStream %} {% for item in chat %} <p> <b>user:</b> {{item.user}} <br> <b>bot:</b> {{item.bot}} <br> </p> {% endfor %} <form action="/send/" method = "post">{% csrf_token %} <input type="text" name="userMessage"> <input type="submit" value="Send to smallest_steps bot"> </form> {% endblock %} How do I create the delay between the user and bot? Thanks -
How do i make a counter that works for me on django Models
i have a question. i am trying to make some counter for my models. i have model- personeel and kwalification. i want to make a couter that counts how mutch personeel got the same kwalification like if 2 personeel got ehbo then it counts 2. def kwalificatietotaal(request): count = Kwalificaties.objects.annotate(ehbo=Count('wel')) teller = 0 if count == count: teller += 1 print(count) return render(request, 'accounts/kwalificatieTotaal.html') class Kwalificaties (models.Model): objects = None TREIN_SOORTEN = ( ('Traxx', 'Traxx'), ('Intercity Direct', 'Intercity Direct'), ('Intercity Nieuwe Generatie', 'Intercity Nieuwe Generatie'), ('Intercity Rijthuig', 'Intercity Rijthuig') ) E_H_B_O = ( ('Wel', 'Wel'), ('Niet', 'Niet'), ) EXTRA_KENNIS = ( ('Bio werkzaamheden', 'Bio werkzaamheden'), ('Kuil werkzaamheden', 'Kuil werkzaamheden'), ('Aardwind werkzaamheden', 'Aardwind werkzaamheden'), ('Airco Monteur', 'Airco Monteur'), ('Z.Z-Deuren Monteur', 'Z.Z-Deuren Monteur'), ('Vooropnamen Elektrisch', 'Vooropnamen Elektrisch'), ('Rijbevoegd Monteur', 'Rijbevoegd Monteur'), ('MTC', 'MTC'), ('EBKC', 'EBKC'), ('Heftruck kwalificatie', 'Heftruck kwalificatie'), ('Hoogwerker kwalificatie', 'Hoogwerker kwalificatie') ) naam = models.ForeignKey(Personeel, null=True, on_delete=models.SET_NULL) treinen = MultiSelectField(max_length=200, choices=TREIN_SOORTEN) ehbo = MultiSelectField(max_length=200, choices=E_H_B_O) extra = MultiSelectField(max_length=200, choices=EXTRA_KENNIS) -
Import models function
I created a models within my page but when I attempted to run the page I received an error response celery_beat_1 | class ClassManager(models.Manager): celery_beat_1 | NameError: name 'models' is not defined I searched for fixes to this error online and most of the responses said to implement the import from django.db import models function. However, this is something I already have configured in my models page. Any idea on how to proceed forward? -
When to use each model relationship in Django?
I've been reading through the Django documentation and looking over some of the other answers on the site for a couple of hours now, yet I still can't get it to sink in. I know this isn't Django specific, but the examples I use will be from a Django project. My question boils down to when is it appropriate to use each: Many-to-many relationships Many-to-one relationships One-to-one relationships One-to-one, more or less makes sense to me. Now for the other two. While I understand the differences between them in isolation, when it comes to using them practically in a project, I get confused. Here is an example: class User(AbstractUser): pass class Listing(models.Model): title = models.CharField(max_length=64) description = models.TextField() class Watchlist(models.Model): user = models.ForeignKey(User, related_name='watchlist', on_delete=models.CASCADE) item = models.ManyToManyField(Listing) class Comment(models.Model): user = models.ForeignKey(User, related_name='comments', on_delete=models.SET_NULL) comment = models.TextField() Would this be the correct use of Many-to-one(ForeignKey) and Many-to-many? Should Watchlist.item be a ForeignKey? Or is M2M correct? Wouldn't it simplify to make the 'Watchlist' part of the User class? (give them an empty list to populate with listing ID's) Why is Watchlist.user not a One-to-one relationship, if each watchlist belongs to a single user, and a user can only have … -
Serpy serializer change the field name
I have the following django code using serpy serializer: class UnitTypeSerializer(TypeSerializer): nameLocal = LocalizationSerializer() um = serpy.Field() It is serialize as 'nameLocal': {'key': 'INTEG', 'en_GB': '', 'ro_RO': None}, 'um':1 I would like to change "nameLocal" to "local" -
Get the value of an IntegerChoices object in Django?
Suppose I have the following Django (3.2) code: class AType(models.IntegerChoices): ZERO = 0, 'Zero' ONE = 1, 'One' TWO = 2, 'Two' a = AType.ZERO How do I get "Zero" (the string associated with a)? This is very similar to this question, except here we only have the IntegerChoices object, and not an associated model object. -
Django behind reverse proxy ?next= issue
I have deployed a Django application behind an nginx reverse proxy. This proxy handles multiple Django applications So the main url is for example https://www.example.com and then I use the reverse proxy to redirect to the specific Django application using subdirectory for example https://www.example.com/myapp The problem is that if I logout from myapp and try to access a page that requires login the redirect link is wrong, instead of https://www.example.com/myapp?next=/mainpage it gives me https://www.example.com/?next=/myapp/mainpage which is wrong since "myapp" cannot listen to requests from https://www.example.com/ Is there any way I can force Django to understand that the default url is https://www.example.com/myapp and not https://www.example.com? Thanks -
Django: Form is not saved and "matching query does not exist" error
I'm trying to create an app to import thanks to an uploaded .csv file data to my database. This is my code and when I try to submit a new file the form is not saved in the database and I'm redirected to the home. I can't also access the file If I create it in admin because I get this error Dataset matching query does not exist. I think my problem is within the ForeignKey and the OneToOneField that I'm not able to save properly? Only the model File is compiled by the user, while Dataset should be filled from the information in the file and linked to the file and the user automatically . Thank you all for your help! VIEWS @login_required def file_upload(request): data = None if request.method == 'POST': file_form = FileForm(request.POST, request.FILES) data_form = DatasetForm(request.POST, request.FILES) raw_file= request.FILES if file_form.is_valid() and data_form.is_valid(): data = request.FILES['file_upload'] data = pd.read_csv(data, header=0, encoding="UTF-8") data_form.instance.user = request.user.profile file_form.instance.user = request.user.profile file_form.instance.filename = raw_file['file_upload'].name Dataset.objects.create( name_user_A = data.iloc[0,1], name_user_B = data.iloc[1,1], [...] ) data_form.save() file_form.save() return redirect('upload_file') else: return redirect('home') else: form = FileForm() context = { 'data': data, 'second_row': second_row, 'file_form': file_form, 'message': message, } return render(request, 'upload_file.html', context) … -
Django simple_jwt auth worked with blank token
My project is running jwt authorization based on the simple_jwt library. Despite the fact that I do not pass the Authorization: Bearer token header, the request passes and returns 201, but if I pass the wrong token, everything works as it should and 401 is returned. My settings: REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework_simplejwt.authentication.JWTAuthentication', ], } SIMPLE_JWT = { 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5), 'REFRESH_TOKEN_LIFETIME': timedelta(days=1), 'ROTATE_REFRESH_TOKENS': False, 'BLACKLIST_AFTER_ROTATION': False, 'UPDATE_LAST_LOGIN': False, 'ALGORITHM': 'HS256', 'SIGNING_KEY': SECRET_KEY, 'VERIFYING_KEY': None, 'AUDIENCE': None, 'ISSUER': None, 'JWK_URL': None, 'LEEWAY': 0, 'AUTH_HEADER_TYPES': ('Bearer',), 'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION', 'USER_ID_FIELD': 'phone_number', 'USER_ID_CLAIM': 'client_phone_number', 'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule', 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',), 'TOKEN_TYPE_CLAIM': 'token_type', 'JTI_CLAIM': 'jti', 'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp', 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5), 'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1), } MyView: class SetPin(generics.CreateAPIView): """Change or set pin code""" serializer_class = serializers.PinSerializer -
django filtering not chained tables
How i can select values from not chained tables in django class Products(models.Model): id = models.CharField(...) name = models.CharField(...) price = models.FloatField(...) image = models.ImageField(...) timestamp = models.DateTimeField(...) class HistoryPrice(models.Model): id = models.CharField(...) name = models.CharField(...) price = models.CharField(...) timestamp = models.CharField(...) Can i get image from Product for a minimal price in HistoryPrice query like this: query_history = HistoryPrice.objects.filter(product__id=product).annotate(min_price=Min('price'))