ModelsΒΆ

This module contains the functions / classes to get information about Django models or to manipulate them.

  • get_users_with_permission() - return the queryset of all users who have specified permission string, including all three possible sources of such users (user permissions, group permissions and superusers).

  • Next functions allow to use parts of queryset functionality on single Django model object instances, supporting spanned relationships without the field lookups:

  • get_meta() / get_verbose_name() - get meta property of Django model field, including spanned relationships with the related (foreign) and reverse-related fields:

    get_verbose_name(profile, 'user__username')
    get_meta(profile, 'verbose_name_plural', 'user__username')
    
  • file_exists() - checks whether Diango file field object exists in the related filesystem.

  • get_object_description() - returns the possibly nested list / dict of django model fields. Uses Model.get_str_fields(), when available, otherwise fallback to Model.__str()__. See get_str_fields model formatting / serialization for more info.

  • get_app_label_model() - parses dot-separated name of app_label / model (natural key) as returned by contenttypes framework. Can be used to parse request content type argument like this:

    app_label, model = get_app_label_model(self.request_get('model', ''))
    
  • get_content_object() - returns content type / content object via contenttypes framework with any valid combination of arguments: object_id, content_type_id, app_label, model. For example, to get the Model instance from the request:

    app_label, model = get_app_label_model(self.request_get('model', ''))
    object_id = self.request_get('content_object_id', None)
    content_type, content_object = get_content_object(object_id=object_id, app_label=app_label, model=model)