Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _extract_model_attrs(model, sa_models):
tables = get_tables()
name = model._meta.db_table
table = tables[name]
fks = [t for t in model._meta.fields
if isinstance(t, (ForeignKey, OneToOneField))]
attrs = {}
rel_fields = fks + list(model._meta.many_to_many)
for fk in rel_fields:
if not fk.column in table.c and not isinstance(fk, ManyToManyField):
continue
if django.VERSION < (1, 8):
parent_model = fk.related.parent_model
else:
parent_model = get_remote_field(fk).model