magic-removal: fix model module lookup
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1652 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
96afbcff43
commit
24c2187082
|
@ -106,15 +106,15 @@ def get_installed_model_modules(core_models=None):
|
|||
# django.models is a special case.
|
||||
for submodule in (core_models or []):
|
||||
_installed_modules_cache.append(__import__('django.models.%s' % submodule, '', '', ['']))
|
||||
for m in get_installed_models():
|
||||
for submodule in getattr(m, '__all__', []):
|
||||
mod = __import__('django.models.%s' % submodule, '', '', [''])
|
||||
try:
|
||||
mod._MODELS
|
||||
except AttributeError:
|
||||
pass # Skip model modules that don't actually have models in them.
|
||||
else:
|
||||
_installed_modules_cache.append(mod)
|
||||
for mod in get_installed_models():
|
||||
try:
|
||||
mod._MODELS
|
||||
except AttributeError:
|
||||
pass # Skip model modules that don't actually have models in them.
|
||||
else:
|
||||
_installed_modules_cache.append(mod)
|
||||
|
||||
|
||||
return _installed_modules_cache
|
||||
|
||||
class LazyDate:
|
||||
|
@ -169,6 +169,7 @@ class RelatedObject(object):
|
|||
self.name = self.opts.module_name
|
||||
self.var_name = self.opts.object_name.lower()
|
||||
|
||||
|
||||
def flatten_data(self, follow, obj=None):
|
||||
new_data = {}
|
||||
rel_instances = self.get_list(obj)
|
||||
|
@ -738,6 +739,7 @@ class Manager(object):
|
|||
# objects -- MySQL returns the values as strings, instead.
|
||||
return [typecast_timestamp(str(row[0])) for row in cursor.fetchall()]
|
||||
|
||||
|
||||
class ModelBase(type):
|
||||
"Metaclass for all models"
|
||||
def __new__(cls, name, bases, attrs):
|
||||
|
@ -839,6 +841,7 @@ class ModelBase(type):
|
|||
|
||||
new_class._prepare()
|
||||
|
||||
|
||||
for field in fields:
|
||||
if field.rel:
|
||||
other = field.rel.to
|
||||
|
@ -847,7 +850,7 @@ class ModelBase(type):
|
|||
else:
|
||||
related = RelatedObject(other._meta, new_class, field)
|
||||
field.contribute_to_related_class(other, related)
|
||||
|
||||
|
||||
return new_class
|
||||
|
||||
class Model(object):
|
||||
|
@ -944,7 +947,7 @@ class Model(object):
|
|||
cls.get_next_in_order = curry(cls.__get_next_or_previous_in_order, is_next=True)
|
||||
cls.get_previous_in_order = curry(cls.__get_next_or_previous_in_order, is_next=False)
|
||||
|
||||
|
||||
|
||||
_prepare = classmethod(_prepare)
|
||||
|
||||
def save(self):
|
||||
|
@ -1007,6 +1010,7 @@ class Model(object):
|
|||
if hasattr(self, '_pre_delete'):
|
||||
self._pre_delete()
|
||||
|
||||
msgs = []
|
||||
cursor = connection.cursor()
|
||||
for related in self._meta.get_all_related_objects():
|
||||
rel_opts_name = related.get_method_name_part()
|
||||
|
@ -1029,9 +1033,12 @@ class Model(object):
|
|||
(backend.quote_name(f.get_m2m_db_table(self._meta)),
|
||||
backend.quote_name(self._meta.object_name.lower() + '_id')),
|
||||
[getattr(self, self._meta.pk.attname)])
|
||||
|
||||
cursor.execute("DELETE FROM %s WHERE %s=%%s" % \
|
||||
(backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)),
|
||||
[getattr(self, self._meta.pk.attname)])
|
||||
|
||||
|
||||
connection.commit()
|
||||
setattr(self, self._meta.pk.attname, None)
|
||||
for f in self._meta.fields:
|
||||
|
@ -1230,12 +1237,13 @@ class Model(object):
|
|||
|
||||
_add_related.alters_data = True
|
||||
|
||||
|
||||
# Handles related many-to-many object retrieval.
|
||||
# Examples: Album.get_song(), Album.get_song_list(), Album.get_song_count()
|
||||
def _get_related_many_to_many(self, method_name, rel_class, rel_field, **kwargs):
|
||||
kwargs['%s__%s__exact' % (rel_field.name, rel_class._meta.pk.name)] = getattr(self, rel_class._meta.pk.attname)
|
||||
return getattr(rel_class._default_manager, method_name)(**kwargs)
|
||||
|
||||
|
||||
# Handles setting many-to-many related objects.
|
||||
# Example: Album.set_songs()
|
||||
def _set_related_many_to_many(self, rel_class, rel_field, id_list):
|
||||
|
|
Loading…
Reference in New Issue