Ticket #13203: 13203_r12773.diff
File 13203_r12773.diff, 1.4 KB (added by , 15 years ago) |
---|
-
django/contrib/contenttypes/generic.py
123 123 return smart_unicode([instance._get_pk_val() for instance in qs]) 124 124 125 125 def m2m_db_table(self): 126 return self.rel.to._meta.db_table 126 # check current model with all its parents for generic relation fields 127 model = self.rel.to 128 object_id_field = model._meta.get_field(self.object_id_field_name) 129 content_type_field = model._meta.get_field(self.content_type_field_name) 127 130 131 # get list with current model and all its parents 132 models = [model] 133 while True: 134 if model._meta.parents: 135 model = model._meta.parents.keys()[0] 136 models += [model] 137 else: 138 break 139 140 for model in models: 141 # check that both fields inside this model 142 if len(set(model._meta.local_fields) & set([object_id_field,content_type_field])) == 2: 143 return model._meta.db_table 144 145 raise Exception("Can't find model with '%s' and '%s' fields" 146 % (self.object_id_field_name, self.content_type_field_name)) 147 128 148 def m2m_column_name(self): 129 149 return self.object_id_field_name 130 150