Exemple #1
0
 def references_model(self, name, app_label):
     name_lower = name.lower()
     if name_lower == self.model_name_lower:
         return True
     if self.field:
         return bool(
             field_references((app_label, self.model_name_lower),
                              self.field, (app_label, name_lower)))
     return False
Exemple #2
0
    def references_model(self, name, app_label):
        name_lower = name.lower()
        if name_lower == self.name_lower:
            return True

        # Check we didn't inherit from the model
        reference_model_tuple = (app_label, name_lower)
        for base in self.bases:
            if (base is not models.Model and isinstance(base, (models.base.ModelBase, str)) and
                    resolve_relation(base, app_label) == reference_model_tuple):
                return True

        # Check we have no FKs/M2Ms with it
        for _name, field in self.fields:
            if field_references((app_label, self.name_lower), field, reference_model_tuple):
                return True
        return False
Exemple #3
0
 def references_field(self, model_name, name, app_label):
     model_name_lower = model_name.lower()
     # Check if this operation locally references the field.
     if model_name_lower == self.model_name_lower:
         if name == self.name:
             return True
         elif self.field and hasattr(
                 self.field,
                 'from_fields') and name in self.field.from_fields:
             return True
     # Check if this operation remotely references the field.
     if self.field is None:
         return False
     return bool(
         field_references(
             (app_label, self.model_name_lower),
             self.field,
             (app_label, model_name_lower),
             name,
         ))