Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Does django have the same level of code generation like Rails?
In rails you can create models, which then create database migrations.
You can generate controllers, views using the command line.
Django has a very similar way of handling database migrations. They are created by calling python manage.py makemigrations and applied with python manage.py migrate
Controllers (urls.py) must be added manually to each app, but by typing one import statement they are ready to be used.
Views are made automatically when an app is initialized. However, they are empty, so creating a app does not give you the automatic CRUD html that rails does. There is generic class based views in Django which have most of data management done for you, along with automatic form generation, but this requires some actual coding albeit very little.
TLDR: In terms of prefab code generation, Rails wins, but any experienced Django developer can include generic views and forms to get the same functionality in minutes.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 10 months ago.
Improve this question
I have just learned python, and am beginning to make a web application using Django / DRF in the back end.
The back end would be similar to a CRUD, or just a CRUD actually, I'm not planning on doing too much processing on requests, but would be queuing jobs for another python script on the server to pick up when needed.
The API I'm building would need to manage a few different entities like Users, Packages, Transactions, Jobs etc, and I plan to manage all of these entities... no ... models... via a rest API.
Do I create an app for each model ? e.g. user_app, package_app, and transaction_app ? or should I create a single app to manage them all?
I'm torn between thinking of Django Apps as actual applications, or Bundles like in PHP/Symfony
There is no obligation to create a new app for every feature that depends on another part of the project logic.
But overall the more you divide into, the easier it will be in the future.
when the project updated and new features added it will be easy to manage it.
Also take a look at some open source projects.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I wonder if a good habit is to have some logic in MySQL database (triggers etc.) instead of logic in Django backend. I'm aware of fact that some functionalities may be done both in backend and in database but I would like to do it in accordance with good practices. I'm not sure I should do some things manually or maybe whole database should be generated by Django (is it possible)? What are the best rules to do it as well as possible? I would like to know the opinion of experienced people.
It is true that if you used a database for your business logic you could get maximum possible performance and security optimizations. However, you would also risk many things such as
No separation of concerns
Being bound to the database vendor
etc.
Also, whatever logic you write in your database won't be version controlled with your app. Thus, whenever you change your database, you will have to create all those things once again.
Instead, use Django ORM. It will create and manage your database based on your models by itself. As a result, whenever you recreate your database, you will just have to run migrations with one single command and you are done.
This will cover most of the situations. And whenever you will need those speeds of stored procedures, Django ORM has you covered as well.
In short, I believe that business logic should be kept out of the database as much as possible.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm still in the process of learning the basics of Django. I have a lot of questions. But the biggest one at the moment is to understand how I reuse admin models, forms and templates to display it on the frontend instead by going on the backend admin control panel.
What I've done so far is to create a url in urls.py, created a view in views.py and added template path, created the template.
Everything works well with that. But how do I just "copy" the admin model that I want so the user that is logged in can edit on the frontend instead?
What do I need to look more into to understand this so I can implement the admin on the frontend?
Though the admin can be configured through a permission system it is nothing that should be exposed to your front end users - it only should be used by users you can fully trust (administrators).
To implement similar functionality on the frontend look into Django's ModelForms and Generic Views which should help you to implement simple CRUD actions rather quickly. If you would like to implement a Javascript based frontend something like Django-REST-Framework might be a good choice to implement something similar for a REST-API.
Nonetheless you could still add a second AdminSite to your project - but as stated above this is not really recommended for security reasons, if you would expose it to the "normal" user.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm working on a project in which scrapy code just has to crawl data from web and store it into database and django application just need to show it as website, both codes(scrapy and django) have nothing to do with each other. I'm wondering what would be the best practice to setup these two parts of the project? Options are:
Create both of them in same folder
Create scrapy project inside Django project
Guide me. Thanks
As #Pramod has pointed out, there is no necessity that they should be in the same folder. But I'll advise you to take the first option - "Both projects in same folder".
My arguments are:
I'd advice against the second option because, it'd just complicate the django project. As django is a framework, there is a default folder structure and implicit meanings in a django project that is time-tested.
why mess with that?
Its better to have two parts of the project in the same folder as it makes more sense as a project.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is it possible to use only some features of Django?
I'm using my own home-made ORM with redis for a webapp using the MVC model. Now I want to know what I have to do to so that I can take advantage of Django's very nice admin.py
Has anyone ever done anything similar?
You can "use only some features of Django", but some parts depend on other parts. Django Admin is very dependent on Django ORM. It is basically a tool for visualizing, creating and editing Django ORM models. Using it with your own "home-made" ORM is virtually impossible.
Take a look at django-nonrel. It forks Django to provide support for non-relational databases (currently MongoDB and Google App Engine). It might help you if your main aim is to use a non-sql db in your project. It still won't help you to easily integrate your custom ORM with Django Admin. So your other option is to write your own admin for your project.