Where does business logic go in Django API - django

I am very new to Django. I am able to set up a basic endpoint thanks to all the tutorials but what many of them miss is Where does one put the business logic of the app? Does it just go in a random file? Do I need to connect it somehow?
File structure that I have now
I think that I should create a file in apps, then add file with any name inside that folder

Related

How to Create an api to upload xml file in django

I need to create an API in Django that will use to take an XML file.
Main Question:
I have created models and serialization and but files that have not to save in Django after extracting the data file will be deleted. now I can not understand the view part(api) please help.
If you wish to upload a file using DRF, you might want to take a look at this topic. It should give you an idea of what to do

bpmn explorer # wso2

I need to customize the Search module of the BPMN Explorer integrated in wso2.
More exactly I want to be able to search using one of the task variables as search parameters.
I have looked in the git repository and came across https://github.com/wso2/carbon-business-process/blob/c6e60e57ab0de5d8de59041647f5cb9b7834d9c7/components/bpmn/org.wso2.carbon.bpmn.ui/src/main/resources/web/bpmn/instance_list_view.jsp
However this script is not in my BPS release (latest available downloaded already).
Could anyone please provide some pointers at least to how I could go about customizing the search function for bpmn explorer ?
Thanks!
Edit:
I managed to modify the gui (searchView.jag file )of the search function, but cannot add functionality for those new fields
You can do the necessary modifications (customize the seach function) to searchModel.jag file for the fields you added in searchView.jag. Please find it (searchModel.jag) under <BPS_HOME>/repository/deployment/server/jaggeryapps/bpmn-explorer/model directory.
If you look at the bpmn-explorer folder you can see three sub-folders namely controller, model and template. Here controller folder includes set of .jag files which are used to check the request is secure or not, hold the session and build basic structure of the rendering pages. .jag files in model folder are used to implement the business logic say as an example invoke activiti rest api to get the process variables, process information, etc. The .jag files in the template folder are used to render the UI elements with appropriate results. Hope this resolves your issue.

Structuring a large API in a Django Project

Right now I have a large project with an equally large API (done using django rest framework). The current structure is something like this:
api
|-----urls.py
|-----models.py
|
----v1
|-----views.py
|-----serializers.py
|-----permissions.py
|-----tests.py
etc
As you can guess, the views.py file is pretty big and I want to refactor this out. Currently I have a few options in front of me, the one I'm leaning towards is to put an 'api/v1' package into each app and use the api app to tie all the urls together and hold views that don't fall into an app.
Does anyone have any experience with this and could provide guidance?
Yes, that's how we're doing it in the project I'm working on at the moment... have an api module under each app in your Django project

Tracking number of downloads in Django

I have a website where I allow people to download files, such as Powerpoint templates that they can reuse.
I added a column to the model that stores information and location of these files called 'Downloads' and in that column I'd like to use it as a counter to track how many times the file has been downloaded.
How would I go about this? Would it be a GET request on the page? Basically I just provide a link to the file and the download starts automatically, so not sure how to relay the fact that the link was clicked back to the model.
Many thanks :-)
If you create a view that handles the GET request you could put the updating code in that view. If your Django-app is not handling the uploading itself, you can create a view that simply redirects to the download link, after updating the counter in the database.
You have several ways to do this:
create a custom view, that "proxies" all files, while keeping track of downloads
create a middleware that does pretty much the same as above, filtering which requests to record
..but none of the above will be applicable if you want to count downloads of collected static files, that will be served directly by your http server, without passing through django. In this case, I'd retrieve the downloads count from the webserver logs; have a look if your webserver allows storing logs to database, otherwise I'd create a cron-running scripts that parses the logfiles and stores the count to a db, accessible from your django application.
Like redShadow said you can create a proxie view. This view could serve the files via mod_xsendfile (if you are using apache as webserver) and set a counter for the downloads.

Django Music API

I'm currently learning django and working on my project. My project involves sharing my composed music and allowing free downloads to people. Is there an API for django that can enable me to upload my music and enable users to download at will?
Any advice is appreciated.
Thanks.
In general I agree with Rajat, what you are trying to achieve (at least the way you described it), can be done with standard Django forms and file handling. However, this app should have already built in a lot of the stuff you require.
You don't need an API to upload files to your servers.You only need a form to do that.And for enabling your users to download content,you only need links to the files.You can use some api to let only authenticated users download the content from your site.
You can add the file user submitted file in media folder
We then later you can locate it's path to make available for your users