For those of you who are exhausted with the MVC framework, why don't you remember it with your own judgment and prejudice? Of course my thinking will be distorted a lot, but I guarantee it will be an interesting experience. This time, I'll use Django as an example.
In one word, the core of MVC would be "HTML that works to some extent with logic divided into coded ER diagrams" Let's explain what's great about this guy, using Model as an example. View and Controller are certainly great technologies, but they are not comparable to the power of Model.
You belonged to the field of writing code in full scratch PHP My boss asks me to change the SQL schema In that case, you have to do the following:
For those who don't know the ER diagram, it's roughly a relational diagram of RDBMS. Making this in Excel is just a pain. Besides, it changes Raw SQL statements are legacy, not something you want to touch at this time I don't want to be able to check the DB test? Is it manual anyway? Please forgive me already By the time I finally got home, I had only sleep time left Let's get rid of such a crappy day
You belonged to a Django site My boss asked me to change the SQL schema In that case, you only need to do the following
It's a lie, but unfortunately true for full scratch PHP writing All you have to do is rewrite the ER diagram code called Model, migrate it, and test it. Many people may find it difficult to hear "Migrate", but all you have to do is open the terminal and type the following two lines.
python manage.py makemigrations
python manage.py migrate
This alone changed the SQL schema. After that, you can get rid of it from the site just by testing
Try it out
Let's experience this wonderful feature
You were told by your boss, "Make a model for a simple TODO app." As a result of organizing, I realized that it is enough to have a table of users and TODO, and a foreign key.
Stop the torture of writing in full scratch PHP. Suddenly jump into Django.
First, you decided to write a Model As a result, I wrote the following code
models.py
from django.db import models
class User(models.Model):
name = models.CharField(max_length=20)
password = models.CharField(max_length=20)
class Todo(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
text = models.CharField(max_length=140)
Strictly wrong code (Django comes standard with the user's model, it's enough to pull it in, and the password isn't encrypted), but it's easy to explain and the boss's eyes are above all. It seems to be cheated, so it will be okay To explain the meaning of the code, the first line pulls Django's models function and inherits it. CharField is just a string type, ForeignKey is just a foreign key With just such a tiny code, your after 5 is guaranteed
Next, let's update the DB That said, it's easy to do. As I explained earlier
python manage.py makemigrations
python manage.py migrate
You will succeed in rewriting the DB with this alone After that, you can do an automatic test or a manual test and leave it from the field Let's watch anime in the free time. I recommend PriPara
Working HTML and logic, that's it Write if in demand
Recommended Posts