|
@ -106,16 +106,16 @@ def get_field(model, fieldname): |
|
|
|
|
|
|
|
|
def get_participacao_composicao(obj): |
|
|
def get_participacao_composicao(obj): |
|
|
new = Composicao() |
|
|
new = Composicao() |
|
|
for new_field, value in [('comissao', obj.cod_comissao), |
|
|
new.comissao, new.periodo = [ |
|
|
('periodo', obj.cod_periodo_comp)]: |
|
|
get_fk_related(Composicao._meta.get_field(name), value) |
|
|
model_field = Composicao._meta.get_field(new_field) |
|
|
for name, value in (('comissao', obj.cod_comissao), |
|
|
value = get_fk_related(model_field, value) |
|
|
('periodo', obj.cod_periodo_comp))] |
|
|
setattr(new, new_field, value) |
|
|
# check if there is already an "equal" one in the db |
|
|
previous = Composicao.objects.filter( |
|
|
already_created = Composicao.objects.filter( |
|
|
comissao=new.comissao, periodo=new.periodo) |
|
|
comissao=new.comissao, periodo=new.periodo) |
|
|
if previous: |
|
|
if already_created: |
|
|
assert len(previous) == 1 |
|
|
assert len(already_created) == 1 # we must never have made 2 copies |
|
|
return previous[0] |
|
|
return already_created[0] |
|
|
else: |
|
|
else: |
|
|
new.save() |
|
|
new.save() |
|
|
return new |
|
|
return new |
|
|