Ticket #13203: 13203_r12773_2.diff
File 13203_r12773_2.diff, 1.4 KB (added by , 15 years ago) |
---|
-
django/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 main_model = self.rel.to 128 object_id_field = main_model._meta.get_field(self.object_id_field_name) 129 content_type_field = main_model._meta.get_field(self.content_type_field_name) 127 130 131 object_id_model = content_type_model = None 132 133 for field, model in main_model._meta.get_fields_with_model(): 134 model = model or main_model 135 if field == object_id_field: 136 object_id_model = model 137 elif field == content_type_field: 138 content_type_model = model 139 140 if object_id_model and object_id_model == content_type_model: 141 return object_id_model._meta.db_table 142 else: 143 raise Exception("Fields '%s' and '%s' are located in different models" 144 % (self.object_id_field_name, self.content_type_field_name)) 145 128 146 def m2m_column_name(self): 129 147 return self.object_id_field_name 130 148