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.

123456789101112131415161718192021
  1. def make_model_tuple(model):
  2. """
  3. Take a model or a string of the form "app_label.ModelName" and return a
  4. corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
  5. assume it's a valid model tuple already and return it unchanged.
  6. """
  7. try:
  8. if isinstance(model, tuple):
  9. model_tuple = model
  10. elif isinstance(model, str):
  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
  16. return model_tuple
  17. except (ValueError, AssertionError):
  18. raise ValueError(
  19. "Invalid model reference '%s'. String model references "
  20. "must be of the form 'app_label.ModelName'." % model
  21. )