Skip to content

Children of Abstract classes are not automatically registered with urls.py

I have the following models:

class Invoice(Model):
    batches = models.ManyToManyField(Batch, blank=True)

    class Meta(Model.Meta):
        abstract = True


class FreelanceInvoice(Invoice):
    ...

In urls.py, children of Model (excluding abstract classes) are registered with urls after they are retrieved like so:

model_classes = {cls.__name__: cls for cls in Model.__subclasses__() if not Model.get_meta(cls, 'abstract', False)}

As Model.__subclasses__() fetches only the immediate subclasses and so FreelanceInvoice in this case is omitted. Instead subclasses should be fetched recursively