i am trying to create a course from my frontend using django form, everything seems fine but when i hit the create button it just refreshes the page without saving to database or throwing back any error, and that is not what i am expecting. create-course.html models.py forms.py Answer this was fixed by just uploading an image, but i wasnt
Tag: django-rest-framework
Is there a way to filter out items from RelatedManager in a ModelViewSet?
I’m using DRF for a simple API, and I was wondering if there’s a way to achieve this behavior: I’ve got two models similar to the following: And their serializers as follows: This returns me an output similar to which is totally fine. But what I’d really want to do is, if a Column has name=None, it’s filtered out from
How To give optional parameter in DRF
Hi Everyone i am created one api, where i will use [city] as first parameter to get result based on city, but i need [id] also as second parameter but [id] is optional, same time we use [id] as second parameter and sometime not, please help me out for ex- 1-get data based on city url=127.0.0.1:8000/api/car/city 2-get data based on
how to create row in model based on data fetched from JSON request from third-party crawling with “best practice”
describe the problem: I want to crawl data from dataforseo , and save them directly in model database through model.create() method with having multi model with multi relation with models so for instance in model A have ManyToMany relation with model B ManyToMany relation with model C ManyToMany relation with model D and model B have relation with model C
Customized CreateModelMixin – Object creation defined in my Model
My rest api view defines only two methods: i have some experience overwriting the list, but i have no experience overwriting create as it seems to be a lot more complicated. What i want to achieve is following. My Request model has a special method which creates instance of Requests – start_request. This method creates not only the instance of
DRF: How to pass extra context data to serializers
I was searching the net and found the similar problem but it doesn’t work in my case, Idk why. I try to put some extra data to context in serializer, but get only 3 default fields: request, view and format and no mention for my custom data. My model: My Serializer: My ModelViewSet: I was debugging it through PyCharm and
Using unittest.mock to mock a DRF response
My example is pretty basic: What I’m trying to do is mock the request to the /core/ URI so it returns a mocked response and not the response from the database. For example, considering unit testing in a CI pipeline when the database isn’t available. The below is what I have, but print(response.data) returns the actual response and not the
Post successful but response is an error on front end
I am posting data through 127.0.0.8000/post/. My post is of course successful cause I am able to see what I posted in the base URL of 127.0.0.8000 successfully but I get the following response on the Django front end. In VS Code I get the following errors in terminal My Views.Py is the following P.S I am also unable to
Python: Run a code after return something
This is an ApiView from my django project: As you see, if client.is_busy is not True, I’m making it True in here. But in this situation, I need to client.is_busy = False after 30 seconds. If I do it under client.save() code, it delays to response. How can I do it? Answer You should consider using timer objects here. e.g.
Checking properties of an object based on separete view (Django|Django-Rest-Framework)
I am using django-rest-framework and React.js. I need a seperate function in the backend to check if CartItem.amount is lower then ProductStock.quantity, if CartItem.product equals ProductStock.id of course (this part does not work). For the same function I need to check if the pricing is the same as in Product model, but suprisingly this part of a function works. What