-
Notifications
You must be signed in to change notification settings - Fork 15
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
Computed ForeignKey fields are broken #155
Comments
Update: My code seems to work as expected if I update the field-computing-method to return the primary key of the related object, instead of directly returning the related object. Ie: @computed(
models.ForeignKey(Foo, models.CASCADE, related_name="+"),
depends=[("self", ["foo1"])],
)
def foo2(self):
return self.foo1.pk This approach will work for me in current project, but I think my initial approach is the more natural/expected way. Thanks, Alex |
@a-p-f Thx for reporting. To be honest, I agree, that returning the model type is more straight forward to comprehend, will see if I can find a workaround for that. |
Hmm...that must be what I'm running into too. I have a field called 'reported_user', and two computed fields 'user1' and 'user2'. All kinds of crashiness. To work around it, I'm just going to handle my logic by overriding the 'save' method. |
Hi there. I have a project that's been using django-computedfields for a while, but I've run into an error when upgrading Django and django-computedfields. It appears you can no longer have a computed ForeignKey field (which my project has been happily doing with django-computedfields==0.1.5).
models.py (Bar has a
computed
ForeignKey
to Foo):test code (just trying to save a Bar instance):
The test code runs fine with:
Django==3.2.25
django-computedfields==0.1.5
But with:
Django==5.1.3
django-computedfields==0.2.6
the
b.save()
call generates:PS: I had a quick look at
examples.test_full.models
, and it looks like you don't have any tests with a computed ForeignKey.The text was updated successfully, but these errors were encountered: