Skip to main content
Getting the object instead of the string in the filter.
Source Link
Max Shawabkeh
  • 38.7k
  • 10
  • 85
  • 92

When you say:

... classes in the file which are an instance of ...

i think you mean "...classes in the file which are subclass of...". If so:

classes = [cls for cls in dir(module)  if issubbclass(getattr(module, cls), models.Model)] 

When you say:

... classes in the file which are an instance of ...

i think you mean "...classes in the file which are subclass of...". If so:

classes = [cls for cls in dir(module) if issubbclass(cls, models.Model)] 

When you say:

... classes in the file which are an instance of ...

i think you mean "...classes in the file which are subclass of...". If so:

classes = [cls for cls in dir(module)  if issubbclass(getattr(module, cls), models.Model)] 
Source Link
mg.
  • 8.1k
  • 1
  • 28
  • 32

When you say:

... classes in the file which are an instance of ...

i think you mean "...classes in the file which are subclass of...". If so:

classes = [cls for cls in dir(module) if issubbclass(cls, models.Model)]