Update build script for client/server use.

This commit is contained in:
luxick
2018-03-07 15:26:22 +01:00
parent 8b0422b1b0
commit e5d0d92de2
20 changed files with 382 additions and 264 deletions

View File

@@ -3,10 +3,21 @@ from common import models
def map_base_fields(cls, db_model):
"""Automatically map fields of db models to common models
:param cls: common.models class to create
:param db_model: database model from which to map
:return: An common.models object
"""
model = cls()
attrs = [attr for attr in db_model._meta.fields]
for attr in attrs:
setattr(model, attr, getattr(db_model, attr))
db_attr = getattr(db_model, attr)
# Check if the attribute is an relation to another db model
# In that case just take its id
if hasattr(db_attr, 'id'):
setattr(model, attr, getattr(db_attr, 'id'))
else:
setattr(model, attr, getattr(db_model, attr))
return model