get_model_or_404

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def get_model_or_404(app_name, model_name):
    """
    Attempt to get a model from the ``AppCache``
    and raise ``Http404`` if it cannot be found
    """
    from django.db.models import get_model
    from django.http import Http404
    
    model_class = get_model(app_name, model_name)
    
    if model_class is None:
        raise Http404("This model does not exist!")

    return model_class

More like this

  1. Decorator for enabling views only when developing by damd 2 years, 9 months ago
  2. get_queryset_or_404 by mattpdx 5 years ago
  3. update_or_create by abhin4v 4 years, 7 months ago
  4. Scoped Cache Compatible with Django Caching Helpers by axiak 5 years, 2 months ago
  5. Dynamic import from an installed app by Archatas 4 years, 1 month ago

Comments

(Forgotten your password?)