Christof
wouldn't surprise me
Anonymous
Depending on user last login and birth date,we have to generate the notification to the user based on weeks
Anonymous
Hi guys can any one help, why use socketio
John
class MessageSerializer(serializers.ModelSerializer): receiver = serializers.SerializerMethodField() class Meta: model = Message fields= ('receiver','message','timestamp',) def get_receiver(self, obj): user = self.context['request'].user if user.is_brand or user.is_distributor: users = User.objects.filter(is_retailer=True).exclude(email=user) return users else: users = User.objects.all().exclude(email=user) return users
John
KeyError at /messageview/2/1/ 'request'
John
Can anyone help me what Is the problem with this, I want to get the current user in the serializer but I'm unable to get it
Mirco
Can anyone help me what Is the problem with this, I want to get the current user in the serializer but I'm unable to get it
you have to pass the request via context when you call the serializer inside the View Or if you use get_serializer method, it will do that for u https://stackoverflow.com/questions/42624104/django-rest-framework-keyerror-request related question
Mirco
it depends on the kind of view u have, the ListAPIView should already inject it via get_serializer_context
John
def post(self, request, sender,receiver): if sender == request.user.id: serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save() sender_message = Message.objects.filter(sender_id=request.user.id, receiver_id=receiver) receiver_message = Message.objects.filter(sender_id=receiver, receiver_id=sender) return Response({"Sender": MessageSerializer(instance=sender_message, many=True).data, "Reciver": MessageSerializer(instance=receiver_message, many=True).data}) else: return Response({'error': 'you are not allowed here'}, status=status.HTTP_400_BAD_REQUEST)
John
Is it required when I pass the serializer like this
John
In listapiview ??
Mirco
Is it required when I pass the serializer like this
MessageSerializer(instance=sender_message, many=True, context={'request': request}).data
John
Still the same issue
John
KeyError at /messageview/2/1/ 'request'
John
This is the way to get the current user in a serializer right
John
?
Mirco
This is the way to get the current user in a serializer right
yup but if the serializer has no context, it's a KeyError
Mirco
KeyError at /messageview/2/1/ 'request'
send the full view with pastebin
John
https://pastebin.com/Lk9y3saW https://pastebin.com/c89WCuif
Mirco
https://pastebin.com/Lk9y3saW https://pastebin.com/c89WCuif
the error is on GET or POST ? paste the traceback inside pastebin
Mirco
https://pastebin.com/Lk9y3saW https://pastebin.com/c89WCuif
with ListAPIView you have get_serializer_context to handle extra context for serializers, the defaults should already contain request
Mirco
?
John
the error is on GET or POST ? paste the traceback inside pastebin
Now I got a new error TypeError at /messageview/2/1/ Object of type User is not JSON serializable
Mirco
How do we serialize the user query_set in Django serializer??? Which is here
you don't have to do that inside the serializer you have to handle the queryset inside get_queryset method of the view
Mr.TD
from django.shortcuts import render,redirect from django.http import HttpRequest from .models import form # Create your views here. def index(request:HttpRequest): detail = form(request.POST['user']) detail2 = form(request.POST['pass1']) detail3 = form(request.POST['pass2']) save = [detail, detail2, detail3] save.save(); return render(request, 'index.html') def chat(request): return render(request, 'chat.html')
Mr.TD
i tried to store data in postgresql but the page through me an erro,
Mr.TD
MultiValueDictKeyError at /index/ 'user'
Mr.TD
can any one help me in this
Mr.TD
pls guys
Mr.TD
ok i try
Mr.TD
super i got it
Mr.TD
thank you very much
John
class MessageSerializer(serializers.ModelSerializer): class Meta: model = Message fields= ('receiver','message','timestamp',) Here receiver is users and I wanna filter these users based on some features like if user is a brand in input And return the users to receiver how do I do that ??
John
Please suggest some effective and efficient way
Mr.TD
def index(request): if request.method == 'POST': detail = form(request.POST['user']) detail2 = form(request.POST['pass1']) detail3 = form(request.POST['pass2']) master = [detail, detail2, detail3] master.save(); return render(request, 'index.html')
Mr.TD
the data is not storing in postgresql
Mr.TD
can any one help
Mr.TD
pls
Jack
can anyone help me i been 3 hours and i dont know the error css dont work for me
Jack
can anyone please help me
Mr.TD
why separate detail, detail2, detail3 ?
then how can i do explain pls
Jack
anyone can help me please :(
Li
I haven't use like that before
Jack
can anybody help me html only loads, css dosnt
Doragonsureiyā
can anybody help me html only loads, css dosnt
Don't ask meta questions like: "Any user of $x here?" "Anyone used technology $y?" "Hello, I need help on $z!" Just ask directly! The better you are at explaining the problem, the more likely you are to get help. Asking smart questions
Mirco
can anybody help me html only loads, css dosnt
Ask directly and explain the issue with details if you wanna a proper answer.
Jack
I have folder/index.html, index is loading OK. Then static/css/styles.css but it's not loading
Jack
Here is my index.html And my styles.css:
Jack
{% load static %} <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href"{% static 'css/styles.css' %}"/> </head> <div class="vertical-align"> <div class="container"> <div class="avatar"></div> <form method="POST"> <input type="text" placeholder="Username"> <input type="password" placeholder="Password"> <input type="button" value="Login"> </form> </div> </div> </html>
Jack
body { padding: 0; margin: 0; font-family: 'Source Sans Pro', Arial, sans-serif; background-color: #84c196; } .vertical-align { display: table-cell; vertical-align: middle; height: 100vh; width: 100vw; } .container{ width: 400px; margin: 0 auto; background-color: #ffffff; box-sizing: border-box; padding: 30px 20px; border-radius: 3px; } .avatar { height: 100px; width: 100px; margin: auto; border-radius: 100px; margin-top: -85px; margin-bottom: 25px; background-color: #588465; box-sizing: border-box; border: 5px solid #588465;
Jack
STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ]
Jack
But its not working, only html is loading...
Son
But its not working, only html is loading...
just look on static file configulation
Jack
just look on static file configulation
Which one is that? You mean settings?
Anonymous
tell your own method
I think u should make a context
Janmay
I want to make a custom field model which seperate input from text field by comma seperator and return as list May someone help me out with it...
Jack
Li
anyone knows how to fix it :(
https://docs.djangoproject.com/en/3.2/intro/tutorial06/
Mounted
Hello everyone, I can't make an infinite scroll datatable. Maybe someone did it? Examples? Thanks in advance
Mounted
I read this article but there is about https://dev.to/coderasha/infinite-scroll-with-django-d0a infinite scrolling of the page, but I need it for the table
The
anyone knows how to fix it :(
Is your issue resolved?
Jack
no
Jack
;/
The
Check on the path if it's the correct one in the settings file
Jack
it is
Jack
sorry still not solved, my bad