def get_app_label(attrs):
    """
    Returns an app_label from attrs
    """
    app_label = None
    try:
        from django.apps import apps
    except ImportError:
        meta = attrs.get('Meta')
        if meta:
            app_label = getattr(meta, 'app_label', None)
        if not app_label:
            app_label = attrs['__module__'].split('.')[-2]
    else:
        app_config = apps.get_containing_app_config(attrs['__module__'])
        if app_config:
            app_label = app_config.label
    return app_label
