django-computedfields icon indicating copy to clipboard operation
django-computedfields copied to clipboard

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

Open sbatdkio opened this issue 1 year ago • 1 comments

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 ?

sbatdkio avatar Feb 15 '24 11:02 sbatdkio

@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.

jerch avatar Feb 15 '24 13:02 jerch