You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

19 lines
692 B

  1. from django.utils import six
  2. def make_model_tuple(model):
  3. """
  4. Takes a model or a string of the form "app_label.ModelName" and returns a
  5. corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
  6. it's assumed to be a valid model tuple already and returned unchanged.
  7. """
  8. if isinstance(model, tuple):
  9. model_tuple = model
  10. elif isinstance(model, six.string_types):
  11. app_label, model_name = model.split(".")
  12. model_tuple = app_label, model_name.lower()
  13. else:
  14. model_tuple = model._meta.app_label, model._meta.model_name
  15. assert len(model_tuple) == 2, "Invalid model representation: %s" % model
  16. return model_tuple