Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One to many relationship , resolver exception when resolving dependency on related set #143

Open
sbatdkio opened this issue Feb 15, 2024 · 1 comment

Comments

@sbatdkio
Copy link

sbatdkio commented Feb 15, 2024

Hi, maybe i did'nt understand the way to handle this, however this is my case:
I have a Campaign/Action_Model one to many relationship & i want a "is_finished" field to be computed in the campaign from the related Action_Models

class  Campaign(ComputedFieldsModel):
  ...
  is_finished = ComputedField(
        BooleanField(default=False),
        depends=[("action_model_set", ["campaign_fk"])],
        compute=is_camapaign_finished,
    )

in another file , i am defining the Action_Model class

class Action_Model(models.Model):
    name = models.CharField(max_length=200, db_index=True)
    campaign_fk = models.ForeignKey(Campaign, on_delete=models.CASCADE)
    ...
    startDate = models.DateField(db_index=True)
    endDate = models.DateField(db_index=True)
   ...

The computedfields resolver says the action_model_set in the Campaign model does not exist as field.
Here is the exception that is raised:
File ".../site-packages/computedfields/graph.py", line 558, in resolve_dependencies descriptor = getattr(cls, symbol) AttributeError: type object 'Campaign' has no attribute 'action_model_set'

Could you tell me what i did wrong ?

@jerch
Copy link
Collaborator

jerch commented Feb 15, 2024

@sbatdkio Hmm, it works with your provided info here. Does that other file, where Action_Model is defined, reside in a different django app?

This pretty much looks like a model resolution issue - can you access action_model_set on Campaign in the shell, if you comment out the computed field temporarily? I'd guess, thats also not possible, maybe got named differently. Alternatively try using an explicit related name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants