In my project I have the Post and Category Model and full working JWT Authentication. I want to create a view, that creates a new Post object, in which author will be assigned to Token owner that I pass in authorization (Bearer Token ) postman.image.example. I dont know how to do it please help. Sorry for my english. Serializer Answer
Tag: django
Add time in django Models.py
I tried subtracting two times in models.py but I got error. Here is my model That I have been working. and BusCompanyRoute have journey length. Now I tried adding these times in using @property decorator in following way but end up getting following error warning as: Class ‘time’ does not define ‘__add__’, so the ‘+’ operator cannot be used on
Django – how to combine multiple filter parameters together, where the number of parameters is variable
I’m trying to implement a search function on Django. If my query is: “a b c”, then I want to to search : select * from table where col LIKE ‘%a%’ and col LIKE ‘%b%’ and col LIKE ‘%c%’ I see I can do that with But how do I make this work for a,b & c. I can’t hard-code
Django group by Choice Field and COUNT Zeros
Consider the following django model: Now, I’d like to group all Ratings by the number of ratings per category like this: which returns a QuerySets like this: Is there a way to include all not-rated dimensions? To achieve an output like: Answer First we will create a dictionary with counts for all dimensions initialised to 0. Next we will query
Setting href to dynamic view name
Trying to pass urls.py view names dynamically to template and then creating hyperlink to each view. How can href be adjusted to handle it. Answer I do not know what stg.addLink returns but to make it work you need to change from to BUT AGAIN it may not work. It depents what stg.editLink returns
Paginator not displaying page numbers Django
I’m trying to use the paginator inbuild Django module so that the user can pass the pages. The problem is that I’ve configured everything as it should, but the pages numbers are not displaying. The place where it should have the numbers is entirely blank. Why can that due to? Home Shop Shop views.py: Any help i would really appreciate
How can I pass in url arguments to an APIRequestFactory put request?
I have been trying for hours but cannot figure out how to pass a url argument through an APIRequestFactory put request. I have tried it through Postman when running my server and the url variable is passed just fine, but when I run it in my tests it stops working. What I mean is that when I send a Postman
Multiple models in Django form
I have the following models: I’d like to create a front-end form which allows a user to review a coach, including a rating for some pre-populated categories. In my head, the form would look something like: I’ve seen Django Formsets in the documentation but these appear to exist for creating multiple forms from the same model as a single form?
How to populate auth.groups and auth.group_permissions tables with initial data in Django project
Context I am using PostgreSQL. I would like to immediately populate the auth.groups and auth.group_permissions tables, after the very first migration of my project. So, after I have set up these tables the way I want them, I dump them by running The resulting file is this The problem To try this, I drop and recreate my db, so that
maximum recursion depth exceeded when using Django redirects
I’m experiencing this error where when I try to redirect a user to a webpage using Django, it showed me this error maximum recursion depth exceeded views.py app’s urls.py Project’s urls.py Did I do something wrong? Did I not add something in settings.py? I’m new to Django Answer When you create the function “redirect”, you ovewrites the built-in function “redirect”