Besides the syntax, what's the difference between using a django abstract model and using plain Python inheritance with django models? Pros and cons?
UPDATE: I think my question was misunderstood and I received responses for the difference between an abstract model and a class that inherits from django.db.models.Model. I actually want to know the difference between a model class that inherits from a django abstract class (Meta: abstract = True) and a plain Python class that inherits from say, 'object' (and not models.Model).
Here is an example:
class User(object):
first_name = models.CharField(..
def get_username(self):
return self.username
class User(models.Model):
first_name = models.CharField(...
def get_username(self):
return self.username
class Meta:
abstract = True
class Employee(User):
title = models.CharField(...
Best Answer
Django will only generate tables for subclasses of
models.Model
, so the former......will cause a single table to be generated, along the lines of...
...whereas the latter...
...won't cause any tables to be generated.
You could use multiple inheritance to do something like this...
...which would create a table, but it will ignore the fields defined in the
User
class, so you'll end up with a table like this...