Ticket #3644: multi-db-modelnameconflict.diff
File multi-db-modelnameconflict.diff, 9.9 KB (added by , 18 years ago) |
---|
-
Users/marc/dev/django/django/db/models/base.py
37 37 new_class._meta.parents.extend(base._meta.parents) 38 38 39 39 model_module = sys.modules[new_class.__module__] 40 model_module_name = model_module.__name__.split('.')[-1] 40 41 41 42 if getattr(new_class._meta, 'app_label', None) is None: 42 43 # Figure out the app_label by looking one level up. … … 44 45 new_class._meta.app_label = model_module.__name__.split('.')[-2] 45 46 46 47 # Bail out early if we have already created this class. 47 m = get_model(new_class._meta.app_label, name, False)48 m = get_model(new_class._meta.app_label, model_module_name+'.'+name, False) 48 49 if m is not None: 50 print 51 print m, name, new_class._meta.app_label, model_module.__name__ 49 52 return m 50 53 51 54 # Add all attributes to the class. … … 68 71 # the first class for this model to register with the framework. There 69 72 # should only be one class for each model, so we must always return the 70 73 # registered version. 71 return get_model(new_class._meta.app_label, name, False)74 return get_model(new_class._meta.app_label, model_module_name+'.'+name, False) 72 75 73 76 class Model(object): 74 77 __metaclass__ = ModelBase -
Users/marc/dev/django/django/db/models/loading.py
107 107 Register a set of models as belonging to an app. 108 108 """ 109 109 for model in models: 110 # Store as ' name: model' pair in a dictionary110 # Store as 'modulename.name: model' pair in a dictionary 111 111 # in the _app_models dictionary 112 module_name = model.__module__.split('.')[-1] 112 113 model_name = model._meta.object_name.lower() 114 key_name = module_name+'.'+model_name 113 115 model_dict = _app_models.setdefault(app_label, {}) 114 116 model_list = _app_model_order.setdefault(app_label, []) 115 117 model_list.append(model_name) 116 if model_dict.has_key( model_name):118 if model_dict.has_key(key_name): 117 119 # The same model may be imported via different paths (e.g. 118 120 # appname.models and project.appname.models). We use the source 119 121 # filename as a means to detect identity. 120 122 fname1 = os.path.abspath(sys.modules[model.__module__].__file__) 121 fname2 = os.path.abspath(sys.modules[model_dict[ model_name].__module__].__file__)123 fname2 = os.path.abspath(sys.modules[model_dict[key_name].__module__].__file__) 122 124 # Since the filename extension could be .py the first time and .pyc 123 125 # or .pyo the second time, ignore the extension when comparing. 124 126 if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]: 125 127 continue 126 model_dict[model_name] = model 128 #if type(model_dict[model_name]) == list: 129 # model_dict[model_name].append(model) 130 #else: 131 # model_dict[model_name] = [model_dict[model_name], model] 132 else: 133 model_dict[key_name] = model -
Users/marc/dev/django/django/db/models/fields/generic.py
44 44 45 45 def get_content_type(self, obj): 46 46 # Convenience function using get_model avoids a circular import when using this model 47 ContentType = get_model("contenttypes", " contenttype")47 ContentType = get_model("contenttypes", "models.contenttype") 48 48 return ContentType.objects.get_for_model(obj) 49 49 50 50 def __get__(self, instance, instance_type=None): -
Users/marc/dev/django/django/db/models/fields/related.py
25 25 key = (module, name) 26 26 # Has the model already been loaded? 27 27 # If so, resolve the string reference right away 28 model = get_model(rel_cls._meta.app_label, field.rel.to, False)28 model = get_model(rel_cls._meta.app_label, 'models.'+field.rel.to, False) 29 29 if model: 30 30 field.rel.to = model 31 31 field.do_related_class(model, rel_cls) -
Users/marc/dev/django/django/core/serializers/xml_serializer.py
195 195 "<%s> node is missing the required '%s' attribute" \ 196 196 % (node.nodeName, attr)) 197 197 try: 198 Model = models.get_model(*model_identifier.split(".")) 198 get_model_args = model_identifier.split(".") 199 get_model_args[1] = 'models.'get_model_args[1] 200 Model = models.get_model(*get_model_args) 199 201 except TypeError: 200 202 Model = None 201 203 if Model is None: -
Users/marc/dev/django/django/core/serializers/python.py
93 93 Helper to look up a model from an "app_label.module_name" string. 94 94 """ 95 95 try: 96 Model = models.get_model(*model_identifier.split(".")) 96 get_model_args = model_identifier.split(".") 97 get_model_args[1] = 'models.'get_model_args[1] 98 Model = models.get_model(*get_model_args) 97 99 except TypeError: 98 100 Model = None 99 101 if Model is None: -
Users/marc/dev/django/django/contrib/admin/views/main.py
224 224 index = staff_member_required(never_cache(index)) 225 225 226 226 def add_stage(request, app_label, model_name, show_delete=False, form_url='', post_url=None, post_url_continue='../%s/', object_id_override=None): 227 model = models.get_model(app_label, model_name)227 model = models.get_model(app_label, 'models.'+model_name) 228 228 if model is None: 229 229 raise Http404("App %r, model %r, not found" % (app_label, model_name)) 230 230 opts = model._meta … … 299 299 add_stage = staff_member_required(never_cache(add_stage)) 300 300 301 301 def change_stage(request, app_label, model_name, object_id): 302 model = models.get_model(app_label, model_name)302 model = models.get_model(app_label, 'models.'+model_name) 303 303 object_id = unquote(object_id) 304 304 if model is None: 305 305 raise Http404("App %r, model %r, not found" % (app_label, model_name)) … … 487 487 488 488 def delete_stage(request, app_label, model_name, object_id): 489 489 import sets 490 model = models.get_model(app_label, model_name)490 model = models.get_model(app_label, 'models.'+model_name) 491 491 object_id = unquote(object_id) 492 492 if model is None: 493 493 raise Http404("App %r, model %r, not found" % (app_label, model_name)) … … 524 524 delete_stage = staff_member_required(never_cache(delete_stage)) 525 525 526 526 def history(request, app_label, model_name, object_id): 527 model = models.get_model(app_label, model_name)527 model = models.get_model(app_label, 'models.'+model_name) 528 528 object_id = unquote(object_id) 529 529 if model is None: 530 530 raise Http404("App %r, model %r, not found" % (app_label, model_name)) … … 741 741 return "%s/" % quote(getattr(result, self.pk_attname)) 742 742 743 743 def change_list(request, app_label, model_name): 744 model = models.get_model(app_label, model_name)744 model = models.get_model(app_label, 'models.'+model_name) 745 745 if model is None: 746 746 raise Http404("App %r, model %r, not found" % (app_label, model_name)) 747 747 if not request.user.has_perm(app_label + '.' + model._meta.get_change_permission()): -
Users/marc/dev/django/django/contrib/contenttypes/models.py
32 32 def model_class(self): 33 33 "Returns the Python model class for this type of content." 34 34 from django.db import models 35 return models.get_model(self.app_label, self.model)35 return models.get_model(self.app_label, 'models.'+self.model) 36 36 37 37 def get_object_for_this_type(self, **kwargs): 38 38 """ -
Users/marc/dev/django/django/contrib/auth/models.py
245 245 raise SiteProfileNotAvailable 246 246 try: 247 247 app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') 248 model = models.get_model(app_label, model_name)248 model = models.get_model(app_label, 'models.'+model_name) 249 249 self._profile_cache = model._default_manager.get(user__id__exact=self.id) 250 250 except (ImportError, ImproperlyConfigured): 251 251 raise SiteProfileNotAvailable