Skip to content

Instantly share code, notes, and snippets.

@jacqueswww
Created January 13, 2017 13:05
Show Gist options
  • Save jacqueswww/f4b1519328b7ea416ed42657da0cb00d to your computer and use it in GitHub Desktop.
Save jacqueswww/f4b1519328b7ea416ed42657da0cb00d to your computer and use it in GitHub Desktop.
Get all django models with FielFields attached to them.
from django.apps import apps
def get_models_with_file_fields():
for model in apps.get_models():
if any(field.__class__.__name__ in ('FileField', 'ImageField')
for field in model._meta.fields):
print(model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment