August 2016
Beginner to intermediate
717 pages
15h 24m
English
The inheritance model allows the use of common fields for two different models. For example, in our App_user model, we cannot determine whether a random recording will be a developer or supervisor.
One solution would be to create two different models, but we would have to duplicate all the common fields such as name, username, and password, as follows:
class Supervisor(models.Model): # Duplicated common fields specialisation = models.CharField(max_length=50, verbose_name="Specialisation") class Developer(models.Model): # Duplicated common fields supervisor = models.ForeignKey(Supervisor, verbose_name="Supervisor")
It would be a shame to duplicate the code, but it is the principle that Django and DRY have to follow. That is why there ...
Read now
Unlock full access