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

MonitorField fails when a used on a required ForeignKey field #140

Open
owais opened this issue Jul 11, 2014 · 0 comments
Open

MonitorField fails when a used on a required ForeignKey field #140

owais opened this issue Jul 11, 2014 · 0 comments

Comments

@owais
Copy link

owais commented Jul 11, 2014

class MyModel(models.Model):
    my_rel = models.ForeignKey('OtherModel')
    my_rel_changed = MonitorField(monitor='my_rel')

m = MyModel()
>> DoesNotExist: MyModel has no my_rel.

It'll work if I change my_rel to

    my_rel = models.ForeignKey('OtherModel', null=True)

The exception is raised here https://github.com/carljm/django-model-utils/blob/master/model_utils/fields.py#L105

def get_monitored_value(self, instance):
    return getattr(instance, self.monitor)
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

1 participant