List the inheritance styles in Django
There are three possible inheritance styles in Django, and they are:
- Abstract Base Classes: This is used when we want to make the parent class hold the information which we don’t want to repeat again in the child class. Abstract Base Classes does not create any database table. It just makes changes in the database table created by the derived class.
- Multi-table Inheritance: This is used when we want to subclass an existing model and there must be a database table designed for each model on its own. It means Multi-table Inheritance creates a database table for each derived class and base class
- Proxy models: This is used to modify the Python level behavior of the model, without modifying the model’s fields. It does not make any changes to the database.
Tips and Tricks
Python | In-place swapping of two numbers
>>> a, b = 10, 20 >>> print(a, b) 10 20 >>> a, b = b, a >>> print(a, b) 20 10
Python | Reversing a String
>>> x = 'PythonWorld' >>> print(x[: : -1]) dlroWnohtyP
Python | Join all items of a list to convert into a single string
>>> x = ["Python", "Online", "Training"] >>> print(" ".join(x)) Python Online Training
Python | Return multiple values from functions
>>> def A(): return 2, 3, 4 >>> a, b, c = A() >>> print(a, b, c) 2 3 4
Python | Print String N times
>>> s = 'Python' >>> n = 5 >>> print(s * n) PythonPythonPythonPythonPython