Videos
How do Django model fields work?
To use methods such as save(), create(), delete(), etc from Model class
As you say, models is a package, that is, a set of classes / methods. For convenience, models and forms are imported only once and the classes they contain are used. Example: models.CharField, otherwise you would have to import the classes one by one (unnecessarily).
Model is a class to create entities in your database.
My understanding so far is, the Django models is used to create the actual columns for the database.
Once I have declared the columns. What is the methods that follow it ? The documentation says this:
Define custom methods on a model to add custom “row-level” functionality to your objects. Whereas Manager methods are intended to do “table-wide” things, model methods should act on a particular model instance.
This is a valuable technique for keeping business logic in one place – the model.
ELI5?
I'm trying to create a comments section using React JS, this is the model I have so far:
class Comment(models.Model):
show = models.CharField(max_length=25)
username = models.CharField(max_length=16)
comment = models.TextField(max_length=1000)
time_stamp = models.DateTimeField()
What kind of methods would be relevant?
Also, I understand that Django comes default with sqlite3. If I was to go into settings.py and change the database to MySQL, would my models create the columns in MySQL instead? And would the backend admin page login take me to the MySQL database?
It means: make the Poll class inherit from the Model base class from the models module.
Do you know what inheritance is? I would start by looking at some examples:
http://parand.com/say/index.php/2009/04/20/python-simple-inheritance-example/
It is basically saying to use all the properties that the Model class has plus whatever you define on your class.
Good luck
in php that would be:
class Poll extends Model
{
var $question;
var $pub_date;
}
Model is a class that is in the models module in Django framework...