Артём
You have to include that context in every *view* you want it in, not relying on templating logic. Override get context data for each view of interest or create a mixin that does it for all the views you want that context in
Yes. I did that. class BaseView(TemplateView): template_name = 'main/base.html' def get_context_data(self, **kwargs): context = super().get_context_data() user = get_object_or_404(User, username=self.kwargs.get('username')) question = Question.objects.filter(user=user) context['answers'] = Answer.objects.filter(question__in=question) return context But django base.html doesn’t see that. Seems like I didn’t pass it.
Sea
How to make users to users chatting system to negotiate like OLX Anyone please give any idea
Arslan
Hi guys, the question is how can I make a request to the model in Django ORM but remove one field from the response
Arslan
how to implement it?
Mirco
how to implement it?
exclude() method of ORM
Mirco
Use values or values_list functions.
Yup, it depends on use case
Arslan
In general, I have such a problem, I need to receive object data in JSON format and I have an ImageField field that is not converted to JSON, so I want to remove it from the request and I think how to do it
Oleg
Guys, dont you know how to handle this case? I have passed token to "sec-websocket-protocol" headers parameter in django channels and everything works great in mozilla firefox, but in chrome and in some other browsers right after connection has established it immediately disconnects with error code 1006. And if Im passing token in queryparams or inside cookie - at these cases everything is fine in all browsers. Could you please point out whats wrong with "sec-websocket-protocol"? Solved this issue. If you pass something in headers parameter Sec-WebSocket-Protocol, then you need to additionally specify it in "accept method" as an additional argument with the name of protocol you used. Because Its not enough to have it in scope and you also need to extract these protocols from scope and place it in accept method.
Amir
hi can anyone help me write below code in a template in jinja? for index, value in enumerate(some_queryset):
Amir
What have you tried? Where are you stuck?
there is a queryset that i passed to a template now I wanna get both value and the index of that value using a for loop
Amir
And what have you tried?
I'm stuck how to implement for loop for that use
Charly
I'm stuck how to implement for loop for that use
Yes but aty least try somethiong, even if you fail show us ehat you have done, search on google how to use wnumerate on templates, or something
lucky
Am new to django After adding dispatch to redirect user That are not allow to access some pages My stop rendering in the template only submit buttom appear
lucky
I mean my form
Nav
What can I do When my inputs are not shown in the admin panel
Nav
Am able to give inputs and able to open admin panel But there are no values
Mahmood
Hi i want to rename a field in unique_together fields for an model And it's give error in the makemigrations I have already database and don't want to drop it I already did some search and found that there is alot of conversation about this But didn't find any solution
Ritesh
I have facing an issue can anyone suggest any solution of this issue:- While generating JWt tokens we have to authenticate request in postman bearer token
Ritesh
With no auth I have also fetch data Can anyone suggest me how I overcome this situation
Mahmood
What error are you facing
ages/django/db/migrations/autodetector.py", line 1457, in _get_altered_foo_together_operations field = new_model_state.get_field(field_name) File ".../lib/python3.10/site-packages/django/db/migrations/state.py", line 762, in get_field return self.fields[field_name]
Jay
I want to sort my objects by price
Jay
But price field belongs to one-to-one related modal
Jay
Can anyone help me in making a query for sorting objects price wise
Mirco
share models in pastebin.org and we'll help u quickly
Mahmood
What error are you facing
I tried to remove the unique_together then migrate , then i rename the field Now i want to readd the unique_together again with the renamed field But it doesn't work
Mahmood
It gives the same error
Jafar
Can i write a json object in json_script templates tag
karakurt
First one cannot be used for creating and updating. You have to override corresponding methods to do it.
Can you give a little example of creating/updating so I understand you better
karakurt
Also you forgot to pass context to the PositionSerializer in the second serializer
What is context? This code works (I took it from my project)
Jay
I have programed for search with pagination and sorting
Jay
When I change page my sort query gets reset
Jay
Can anyone help me
Rojitech
When I change page my sort query gets reset
Are the query not shown in the URL parameters
Azizbek Xushnazarov
What is context? This code works (I took it from my project)
If you use generic views they send request and view through the context attribute of the serializer. But In your case PositionSerializer cannot access the request and view. So it's always a good habit to pass parent serializer's context to child serializers.
Ôscar
Guys my media file doesn't load when debug = False
Ôscar
How to solve this problem
Azizbek Xushnazarov
Can you give a little example of creating/updating so I understand you better
https://www.django-rest-framework.org/api-guide/relations/#writable-nested-serializers
karakurt
https://www.django-rest-framework.org/api-guide/relations/#writable-nested-serializers
But what does it have to do with to_representation method? Sorry, I'm very stupid in DRF
Alberto
Hi, I need to update the user session from outside views (in a Celery task). Currently I'm passing the user session id to the task, and then initializing a Sesion object and updating the required value. The problem is that I cannot access this value then from request.session. I can't find any relevant information about this, any suggestions on how to solve this?
Saqib
Hello everyone i am stuck in django payment . My question is how user can send money to another user on his bank account like amazon customer send money to Amazon seller bank accounts
jaxx
class UsersCount(APIView): def get(self, request): users = Account.objects.count() serializer = AccountSerializer(users, many=True) return Response(serializer.data) This one shows "int object is not iterable". Anyone please explain
Shahrukh
Can anyone please me in creating api
Doragonsureiyā
Can anyone please me in creating api
This is neither a job board nor a bulletin board.
Maksim
Hi, guys! How to add search system in header right from buttons(setting, create an article, everything articles)
Maksim
I to add this search system in header she is down but not to left. Help me, please
Maksim
For example, if search system right from button he's under button elif left right button he's on one line
Raadin
Guys my media file doesn't load when debug = False
Did you follow the static document in django website and run "python manage.py collectstatic" ??
Raadin
I solved
Good job
Ôscar
In short, you must host that media file
Ôscar
I used claudinary
Ôscar
So easy and effective
Ôscar
But now I have another problem
Ôscar
My textfield
Ôscar
When I inject it in html template
Ôscar
All text appears in one p tag so I used linebreaks filter to make it appears in multiple p tags
Ôscar
The whole idea is that I have mixed text between Arabic and English p tags, and when I make direction : "rtl" It does not target p tags of Arabic only But the whole p tags in my div
Ôscar
I don't know how to solve this problem
Ôscar
I think no one understands my problem 😂😂😂😂😂😂
Gnomic
I have create the template but it still show me this error
Ôscar
I solved it
Ôscar
I added some regex logic in my templates
Fife
Does anyone have a sample code for callback function/closure