Ticket #3644: multi-db-modelnameconflict-2.diff

File multi-db-modelnameconflict-2.diff, 9.5 KB (added by marc@…, 8 years ago)

cleaned up version

  • Users/marc/dev/django/django/db/models/base.py

     
    3737                new_class._meta.parents.extend(base._meta.parents)
    3838
    3939        model_module = sys.modules[new_class.__module__]
     40        model_module_name = model_module.__name__.split('.')[-1]
    4041
    4142        if getattr(new_class._meta, 'app_label', None) is None:
    4243            # Figure out the app_label by looking one level up.
     
    4445            new_class._meta.app_label = model_module.__name__.split('.')[-2]
    4546
    4647        # 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)
    4849        if m is not None:
    4950            return m
    5051
     
    6869        # the first class for this model to register with the framework. There
    6970        # should only be one class for each model, so we must always return the
    7071        # registered version.
    71         return get_model(new_class._meta.app_label, name, False)
     72        return get_model(new_class._meta.app_label, model_module_name+'.'+name, False)
    7273
    7374class Model(object):
    7475    __metaclass__ = ModelBase
  • Users/marc/dev/django/django/db/models/loading.py

     
    107107    Register a set of models as belonging to an app.
    108108    """
    109109    for model in models:
    110         # Store as 'name: model' pair in a dictionary
     110        # Store as 'modulename.name: model' pair in a dictionary
    111111        # in the _app_models dictionary
     112        module_name = model.__module__.split('.')[-1]
    112113        model_name = model._meta.object_name.lower()
     114        key_name = module_name+'.'+model_name
    113115        model_dict = _app_models.setdefault(app_label, {})
    114116        model_list = _app_model_order.setdefault(app_label, [])
    115117        model_list.append(model_name)
    116         if model_dict.has_key(model_name):
     118        if model_dict.has_key(key_name):
    117119            # The same model may be imported via different paths (e.g.
    118120            # appname.models and project.appname.models). We use the source
    119121            # filename as a means to detect identity.
    120122            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__)
    122124            # Since the filename extension could be .py the first time and .pyc
    123125            # or .pyo the second time, ignore the extension when comparing.
    124126            if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]:
    125127                continue
    126         model_dict[model_name] = model
     128        else:
     129            model_dict[key_name] = model
  • Users/marc/dev/django/django/db/models/fields/generic.py

     
    4444           
    4545    def get_content_type(self, obj):
    4646        # 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")
    4848        return ContentType.objects.get_for_model(obj)
    4949       
    5050    def __get__(self, instance, instance_type=None):
  • Users/marc/dev/django/django/db/models/fields/related.py

     
    2525    key = (module, name)
    2626    # Has the model already been loaded?
    2727    # 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)
    2929    if model:
    3030        field.rel.to = model
    3131        field.do_related_class(model, rel_cls)
  • Users/marc/dev/django/django/core/serializers/xml_serializer.py

     
    195195                "<%s> node is missing the required '%s' attribute" \
    196196                    % (node.nodeName, attr))
    197197        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)
    199201        except TypeError:
    200202            Model = None
    201203        if Model is None:
  • Users/marc/dev/django/django/core/serializers/python.py

     
    9393    Helper to look up a model from an "app_label.module_name" string.
    9494    """
    9595    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)
    9799    except TypeError:
    98100        Model = None
    99101    if Model is None:
  • Users/marc/dev/django/django/contrib/admin/views/main.py

     
    224224index = staff_member_required(never_cache(index))
    225225
    226226def 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)
    228228    if model is None:
    229229        raise Http404("App %r, model %r, not found" % (app_label, model_name))
    230230    opts = model._meta
     
    299299add_stage = staff_member_required(never_cache(add_stage))
    300300
    301301def 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)
    303303    object_id = unquote(object_id)
    304304    if model is None:
    305305        raise Http404("App %r, model %r, not found" % (app_label, model_name))
     
    487487
    488488def delete_stage(request, app_label, model_name, object_id):
    489489    import sets
    490     model = models.get_model(app_label, model_name)
     490    model = models.get_model(app_label, 'models.'+model_name)
    491491    object_id = unquote(object_id)
    492492    if model is None:
    493493        raise Http404("App %r, model %r, not found" % (app_label, model_name))
     
    524524delete_stage = staff_member_required(never_cache(delete_stage))
    525525
    526526def 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)
    528528    object_id = unquote(object_id)
    529529    if model is None:
    530530        raise Http404("App %r, model %r, not found" % (app_label, model_name))
     
    741741        return "%s/" % quote(getattr(result, self.pk_attname))
    742742
    743743def 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)
    745745    if model is None:
    746746        raise Http404("App %r, model %r, not found" % (app_label, model_name))
    747747    if not request.user.has_perm(app_label + '.' + model._meta.get_change_permission()):
  • Users/marc/dev/django/django/contrib/contenttypes/models.py

     
    3232    def model_class(self):
    3333        "Returns the Python model class for this type of content."
    3434        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)
    3636
    3737    def get_object_for_this_type(self, **kwargs):
    3838        """
  • Users/marc/dev/django/django/contrib/auth/models.py

     
    245245                raise SiteProfileNotAvailable
    246246            try:
    247247                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)
    249249                self._profile_cache = model._default_manager.get(user__id__exact=self.id)
    250250            except (ImportError, ImproperlyConfigured):
    251251                raise SiteProfileNotAvailable
Back to Top