Changed name from .rel to .remote_field for remote accessors.

- Legacy-Id: 14665
This commit is contained in:
Henrik Levkowetz 2018-02-21 23:56:36 +00:00
parent a4768bb514
commit 36b5e2ef8e
5 changed files with 25 additions and 20 deletions

View file

@ -96,10 +96,10 @@ class Command(AppCommand):
for field in model._meta.fields:
if isinstance(field, (models.ForeignKey, models.OneToOneField)):
#debug.show('field.name')
#debug.pprint('dir(field.rel.to)')
#debug.pprint('dir(field.remote_field.to)')
#exit()
rel_app=field.rel.to._meta.app_label
rel_model_name=field.rel.to.__name__
rel_app=field.remote_field.to._meta.app_label
rel_model_name=field.remote_field.to.__name__
if rel_model_name == model_name:
# foreign key to self class -- quote
# the rmodel_name
@ -111,10 +111,10 @@ class Command(AppCommand):
name=field.name,
app=rel_app,
module=rel_app.split('.')[-1],
model=field.rel.to,
model=field.remote_field.to,
model_name=rel_model_name,
rmodel_name=rmodel_name,
resource_name=field.rel.to.__name__.lower(),
resource_name=field.remote_field.to.__name__.lower(),
))
imports[rel_app]["module"] = rel_app
imports[rel_app]["names"].append(rel_model_name)
@ -124,10 +124,10 @@ class Command(AppCommand):
m2m_keys = []
for field in model._meta.many_to_many:
#debug.show('field.name')
#debug.pprint('dir(field.rel.to)')
#debug.pprint('dir(field.remote_field.to)')
#exit()
rel_app=field.rel.to._meta.app_label
rel_model_name=field.rel.to.__name__
rel_app=field.remote_field.to._meta.app_label
rel_model_name=field.remote_field.to.__name__
if rel_model_name == model_name:
# foreign key to self class -- quote
# the rmodel_name
@ -139,10 +139,10 @@ class Command(AppCommand):
name=field.name,
app=rel_app,
module=rel_app.split('.')[-1],
model=field.rel.to,
model=field.remote_field.to,
model_name=rel_model_name,
rmodel_name=rmodel_name,
resource_name=field.rel.to.__name__.lower(),
resource_name=field.remote_field.to.__name__.lower(),
))
imports[rel_app]["module"] = rel_app
imports[rel_app]["names"].append(rel_model_name)

View file

@ -44,8 +44,10 @@ def save_document_in_history(doc):
# copy many to many
for field in doc._meta.many_to_many:
if field.rel.through and field.rel.through._meta.auto_created:
setattr(dochist, field.name, getattr(doc, field.name).all())
if field.remote_field.through and field.remote_field.through._meta.auto_created:
hist_field = getattr(dochist, field.name)
hist_field.clear()
hist_field.set(getattr(doc, field.name).all())
# copy remaining tricky many to many
def transfer_fields(obj, HistModel):

View file

@ -192,7 +192,7 @@ def fill_in_wg_drafts(group):
group.drafts.append(a)
else:
group.rfcs.append(a)
a.rel = RelatedDocument.objects.filter(source=a.document,relationship_id__in=['obs','updates']).distinct()
a.remote_field = RelatedDocument.objects.filter(source=a.document,relationship_id__in=['obs','updates']).distinct()
a.invrel = RelatedDocument.objects.filter(target=a,relationship_id__in=['obs','updates']).distinct()
@ -1112,7 +1112,8 @@ def customize_workflow(request, group_type=None, acronym=None):
group.groupstatetransitions_set.filter(state=state).delete()
else:
transitions, _ = GroupStateTransitions.objects.get_or_create(group=group, state=state)
transitions.next_states = next_states
transitions.next_states.clear()
transitions.next_states.set(next_states)
return redirect("ietf.group.views.customize_workflow", group_type=group.type_id, acronym=group.acronym)

View file

@ -91,5 +91,7 @@ def copy_many_to_many_for_history(history_obj, obj):
"""Copy basic many-to-many fields from obj to history_obj."""
# copy many to many
for field in obj._meta.many_to_many:
if field.rel.through and field.rel.through._meta.auto_created:
setattr(history_obj, field.name, getattr(obj, field.name).all())
if field.remote_field.through and field.remote_field.through._meta.auto_created:
history_field = getattr(history_obj, field.name)
history_field.clear()
history_field.set(getattr(obj, field.name).all())

View file

@ -46,10 +46,10 @@ class Command(BaseCommand):
raise
if foreign_model == field.model:
return
foreign_field_name = field.rel.name
foreign_accessor_name = field.rel.get_accessor_name()
foreign_field_name = field.remote_field.name
foreign_accessor_name = field.remote_field.get_accessor_name()
if verbosity > 1:
print " %s <- %s -> %s.%s" % (field.model.__name__, field.rel.through._meta.db_table, foreign_model.__module__, foreign_model.__name__),
print " %s <- %s -> %s.%s" % (field.model.__name__, field.remote_field.through._meta.db_table, foreign_model.__module__, foreign_model.__name__),
try:
used = set(foreign_model.objects.values_list(foreign_field_name, flat=True))
except FieldError:
@ -66,7 +66,7 @@ class Command(BaseCommand):
print " ok"
else:
if used - exists:
print "\n%s.%s <- %s -> %s.%s ** Bad key values:\n " % (field.model.__module__, field.model.__name__, field.rel.through._meta.db_table, foreign_model.__module__, foreign_model.__name__), list(used - exists)
print "\n%s.%s <- %s -> %s.%s ** Bad key values:\n " % (field.model.__module__, field.model.__name__, field.remote_field.through._meta.db_table, foreign_model.__module__, foreign_model.__name__), list(used - exists)
for conf in tqdm([ c for c in apps.get_app_configs() if c.name.startswith('ietf.')], desc='apps', disable=verbose):
if verbosity > 1: