A django model mixin that makes it easy to react to field value changes on models. Supports an API similar to the model clean method.

adamhaney, updated 🕥 2022-01-21 19:14:12

django-ondelta

A django model mixin that makes it easy to react to field value changes on models. Supports an API similar to the model clean method.

Quick Start

Given that I have the model

class MyModel(models.Model):
    mai_field = models.CharField()
    other_field = models.BooleanField()

And I want to be notified when mai_field's value is changed and persisted I would simply need to modify my model to include a ondelta_mai_field method.

from ondelta.models import OnDeltaMixin

class MyModel(OnDeltaMixin):
    mai_field = models.CharField()
    other_field = models.BooleanField()

    def ondelta_mai_field(self, old_value, new_value):
        print("mai field had the value of {}".format(old_value))
        print("but after we called save it had the value of {}".format(new_value))

This is the easiest method to watch a single field for changes, but what if we want to perform an action that has an aggregate view of all of the fields that were changed? OnDeltaMixin provides an ondelta_all method for these cases; it is only called once for each save.

from ondelta.models import OnDeltaMixin

class MyModel(OnDeltaMixin):
    mai_field = models.CharField()
    other_field = models.BooleanField()

    ondelta_all(self, fields_changed):
        if 'mai_field' in fields_changed and 'other_field' in fields_changed:
            print("Both fields changed during this save!")

Unsupported Field Types

Some field types are not supported: ManyToManyField, reverse ManyToManyField, reverse ForeignKey, and reverse OneToOneField relations. If you create an ondelta_field_name method for one of these fields, it will not be called when that field is changed.

Help

I like to help people as much as possible who are using my libraries, the easiest way to get my attention is to tweet @adamhaney or open an issue. As long as I'm able I'll help with any issues you have.

Issues

Bump ipython from 2.4.1 to 7.16.3

opened on 2022-01-21 19:14:12 by dependabot[bot]

Bumps ipython from 2.4.1 to 7.16.3.

Release notes

Sourced from ipython's releases.

7.9.0

No release notes provided.

7.8.0

No release notes provided.

7.7.0

No release notes provided.

7.6.1

No release notes provided.

7.6.0

No release notes provided.

7.5.0

No release notes provided.

7.4.0

No release notes provided.

7.3.0

No release notes provided.

7.2.0

No release notes provided.

7.1.1

No release notes provided.

7.1.0

No release notes provided.

7.0.1

No release notes provided.

7.0.0

No release notes provided.

7.0.0-doc

No release notes provided.

7.0.0rc1

No release notes provided.

7.0.0b1

No release notes provided.

6.2.1

No release notes provided.

... (truncated)

Commits


Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/adamhaney/django-ondelta/network/alerts).

Bump django from 1.11.23 to 2.2.24

opened on 2021-06-10 18:38:50 by dependabot[bot]

Bumps django from 1.11.23 to 2.2.24.

Commits
  • 2da029d [2.2.x] Bumped version for 2.2.24 release.
  • f27c38a [2.2.x] Fixed CVE-2021-33571 -- Prevented leading zeros in IPv4 addresses.
  • 053cc95 [2.2.x] Fixed CVE-2021-33203 -- Fixed potential path-traversal via admindocs'...
  • 6229d87 [2.2.x] Confirmed release date for Django 2.2.24.
  • f163ad5 [2.2.x] Added stub release notes and date for Django 2.2.24.
  • bed1755 [2.2.x] Changed IRC references to Libera.Chat.
  • 63f0d7a [2.2.x] Refs #32718 -- Fixed file_storage.test_generate_filename and model_fi...
  • 5fe4970 [2.2.x] Post-release version bump.
  • 61f814f [2.2.x] Bumped version for 2.2.23 release.
  • b8ecb06 [2.2.x] Fixed #32718 -- Relaxed file name validation in FileField.
  • Additional commits viewable in compare view


Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/adamhaney/django-ondelta/network/alerts).

ondelta_[Field] is giving incorrect value for _state.adding

opened on 2018-08-20 14:57:32 by atb00ker

ondelta_[Field] is giving incorrect value for _state.adding

def clean(self):
    print(self._state.adding) # Output: True
    ...

def ondelta_name(self, old_value, new_value):
    print(self._state.adding) # Output: False
    ...

Expected Output: True

TypeError: add() argument after * must be a sequence, not RelatedManager

opened on 2015-01-12 18:19:00 by smcoll

Here are the models:

``` class Foo(OnDeltaModel): name = models.CharField(max_length=50) is_public = models.BooleanField(default=False)

class Bar(models.Model): foo = models.ForeignKey(models.Model, related_name='items'): ```

And the traceback:

```

foo.save() Traceback (most recent call last): File "[...]python2.7/site-packages/IPython/core/interactiveshell.py", line 2827, in run_code exec code_obj in self.user_global_ns, self.user_ns File "", line 1, in c.save() File "[...]python2.7/site-packages/ondelta/models.py", line 75, in save self._ondelta_dispatch_notifications() File "[...]python2.7/site-packages/ondelta/models.py", line 55, in _ondelta_dispatch_notifications setattr(self._ondelta_shadow, field, changes['new']) File "[...]python2.7/site-packages/django/db/models/fields/related.py", line 404, in set manager.add(*value) TypeError: add() argument after * must be a sequence, not RelatedManager ```

It happens because 'items' returns as a field name in the _ondelta_fields_to_watch() method of Foo, although it's not a field. django.db.models.options.get_all_field_names() includes reverse relation names.

Adam Haney

Serial Entrepreneur, VP of Engineering @invisible-tech, former CTO @eat-on-the-house, @bellhops,

GitHub Repository