Kapil
can it be done with some queryset?
محمد دلشاد
Kapil
idk about that
ok thanks for your efforts I will try something and update you if I'm able to resolve it
محمد دلشاد
and thats no effort
Mehmet
can it be done with some queryset?
Item.objects.values("id").annotate(avg1=models.Avg("shipping_cost")) That is sample query for grouped aggregation
Pam
there are lots of videos for that in youtube
can you please send any useful link ?
Mehmet
Place your group fields in values and annotate with a fictive key and db function as above.
Kapil
can you please send any useful link ?
I don't have any link with me you can search for "post request in django" or something like that an go though some videos you will get the idea
Kapil
can you please send any useful link ?
https://youtu.be/UxTwFMZ4r5k I haven't seen this video but I this this may help you
Kapil
*think
Mehmet
No, you should not use aggregate function but annotate function.
Mehmet
Sample above is obvious enough, it extracts the avg shipping cost per id.
Felipe
Hey guys, I hope you're all good! I'm facing a weird behavior on my Django application. I'm using the Django rest framework. I have an endpoint that receives a POST and creates a resource. Running the server and testing by Postman making the requests manually everything works just fine, but when I try to run tests using py.test it's failing. Now comes the weird part... One of the parameters sent on the payload is missing on the tests and is present on the regular requests made by the postman. I've checked the validated_data['parameter_name'] and on Postman it's coming correctly, but on the tests, it's not coming. I already checked the data that is being sent and it's ok. Does someone already get some error like this? Any idea of what could be the problem?
Kapil
Sample above is obvious enough, it extracts the avg shipping cost per id.
I have replaced Items and models with my model name and im getting error that models has no attribute 'Avg'
Felipe
How is it failing, do you get any error message, any stack trace etc.?
I'm not getting errors, but one of the parameters is not present on the validated_data
Kapil
Teacher.objects.values("id").annotate(avg1=Rating.Avg("value"))
Mehmet
Teacher.objects.values("id").annotate(avg1=Rating.Avg("value"))
That is a wrong query, Avg is static method of models. Could you tell me how your Rating and Teacher connected?
Mehmet
is Rating connected to Teacher with foreign key? I mean one teacher instance has many Rating. Am I right?
Kapil
yes
Mehmet
Rating.objects.values("teacher_id").annotate(avg_rating=models.Avg("value"))
Mehmet
this will fetch lazy queryset of dictionaries not Rating object.
Kapil
models should be as it is or replace it with rating?
Mehmet
models should be as it is or replace it with rating?
I assumed you already had Rating model which is connected to Teacher with ForeignKey
Kapil
yes
Mehmet
Then there should not be issue left.
Kapil
rating model has teacher which takes id of teachers
Mehmet
Have you got the approach I prepared or do you want me to create an exact query for you?
Anonymous
Do anyone have any idea how to mock a function in testing?
Mehmet
I tried this query but it is giving the same error
I do not know, I prepare the same query in my ORM before sending you with a similar ForeignKey connection, and I can say it is successfully working.
Kapil
I just wanted to know one thing , it is possible to create a query to get my desired outcome?
Mehmet
I just wanted to know one thing , it is possible to create a query to get my desired outcome?
You can mimic almost every SQL expression with the help of Django ORM. I hope you got the path, it is really simple but I could not find a way to help you more.
M
hi anyone willing to teach me practical Django web development ( 0 to web application development ) or can suggest a learning path . PS: I tried online resources in pin post but not moving more on satisfactory level
Doragonsureiyā
hi anyone willing to teach me practical Django web development ( 0 to web application development ) or can suggest a learning path . PS: I tried online resources in pin post but not moving more on satisfactory level
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
Anonymous
So I'm writing testcases for my project..to create a user Im using serializer to save data...in the serializer I overidden create method which calls a sendEmail function wen the user is Created..the email will be sent using aws I configured aws credentials in my local using aws config file Wen I push into git the test cases r failing How to mock the email send function inorder to pass the testcase?
Abdullah
hi guys.i tried deploy my django site with pythonanywhere but i get a this result:
Abdullah
Something went wrong :-( This website is hosted by PythonAnywhere, an online hosting environment. Something went wrong while trying to load it; please try again later.
Nikita Deriabin
Hi guys, I have problem.I get syntax error") from exc", when I write a command "python manage.py collectstatic". Can you help me with it?
Anonymous
Hi guys, I have problem.I get syntax error") from exc", when I write a command "python manage.py collectstatic". Can you help me with it?
this is because python version error hai if you're using just *python* on linux or Debian it's python 2 , use python3 manage.py *option*
Manuel
someone can help me please
Manuel
class UserAPI(viewsets.ViewSet): def list(self, request): queryset = User.objects.all() serializer = UserSerializer(queryset, many=True) return Response(serializer.data)
Manuel
class UserSerializer(serializers.Serializer): class Meta: model=User fields="all"
Manuel
and I got no json on my DRF
Manuel
this is the result
Manuel
HTTP 200 OK Allow: GET, HEAD, OPTIONS Content-Type: application/json Vary: Accept [ {}, {}, {}, {}, {}, {}, {}, {} ]
Manuel
I don't understand
Manuel
why is not working properly
Manuel
someone can help me please
Manuel
ok ok
Manuel
how would it be
Abel
Hey guys how can I make progress request from django rest framework
Mehmet
What do you mean by progress request?
abcde
In many tutorials they use ArticleListView(ListView) for using generic list view and ArticleDetailView(DetailView) for using generic detail view . Is it compulsory to use it that way . Can we write just Article(ListView) for using generic list view
Pam
Hello guys can anyone tell me how to fetch django rest api in frontend ?
Pam
Like i want to use that rest api which i have created using django rest framework in frontend of my application.
Pam
React js
Pam
Any idea
Pam
ok
Anonymous
Hi all I am learning Django framework I have a one doubt please clarify
Anonymous
Why Cloudnot send photo this group
Karthik
Why Cloudnot send photo this group
This group don't allow medi
Karthik
Media
Doragonsureiyā
This group don't allow medi
To share code or error tracebacks please use an online pasting service, here is a list of suggested sites: - https://del.dog - https://dpaste.org - https://linkode.org - https://hastebin.com - https://bin.kv2.dev
Doragonsureiyā
Why Cloudnot send photo this group
Read the rules before any activity: @PythonRules
Yesu
Hi all, I have to display the image in Django template and I am retrieving it using db {{model.imagefield.url}} But it is not shown in front end. Steps tried, 1- media URL and root are defined 2- static(settings.media_url, document_root=settings.media_root) defined in urlpatterns 3- image also Been upload to media folder When I am checking the google console I couldn't see media folder
Yesu
Can anyone help on this