MCPcopy
hub / github.com/django/django / normalize_together

Function normalize_together

django/db/models/options.py:64–83  ·  view source on GitHub ↗

option_together can be either a tuple of tuples, or a single tuple of two strings. Normalize it to a tuple of tuples, so that calling code can uniformly expect that.

(option_together)

Source from the content-addressed store, hash-verified

62
63
64def normalize_together(option_together):
65 """
66 option_together can be either a tuple of tuples, or a single
67 tuple of two strings. Normalize it to a tuple of tuples, so that
68 calling code can uniformly expect that.
69 """
70 try:
71 if not option_together:
72 return ()
73 if not isinstance(option_together, (tuple, list)):
74 raise TypeError
75 first_element = option_together[0]
76 if not isinstance(first_element, (tuple, list)):
77 option_together = (option_together,)
78 # Normalize everything to tuples
79 return tuple(tuple(ot) for ot in option_together)
80 except TypeError:
81 # If the value of option_together isn't valid, return it
82 # verbatim; this will be picked up by the check framework later.
83 return option_together
84
85
86def make_immutable_fields_list(name, data):

Callers 4

remove_model_optionsMethod · 0.90
from_modelMethod · 0.90
__init__Method · 0.90
contribute_to_classMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected