Django/Python: confusion on class Classname(models.Model) parameter
Question: I cannot understand the models.Model parameter and what exactly it does here.
I am learning django on the job and this is my first software project. Here is
a piece:

    
    
    class DocumentRequest(models.Model):
        #contact info fields
        first_name = models.CharField(max_length=255)
        last_name = models.CharField(max_length=255)
    

Throughout the first part of code, we used Charfield, IntegerField,
DateTimeField and so on. It seems to be the Model class of the models file
that allows these things to be used, if I'm correct. I don't understand why
you would use models.Model as a parameter, why not just import the "Model"
class and use these calls (models.CharField, etc)?

Thanks


Answer: What you have here is `class inheritance`.

There is a `Model` class that lives in a `django.db.models` module. You can
actually check the source code [here, currently starting at line
371](https://github.com/django/django/blob/master/django/db/models/base.py).
As you can see as you scroll down, there are a bunch of methods. Methods are
functions defined inside of the class. When you `subclass` one class during
the declaration of another it inherits those methods (and other goodness) that
was defined in the parent class.

Your `DocumentRequest` class will have everything that was defined in `Model`
class + new stuff specific to your new class. The concept of `class
inheritance` saves us a lot of trouble and is absolutely core to understanding
object oriented programming.

You can do this:

    
    
    dr = DocumentRequest()
    dr.first_name = "Mark"
    dr.last_name = "Twain"
    dr.save()  # save() method exists, we can use it right away!
    

