Anonymising objects¶
Models¶
Call this to anonymise the private fields on the object.
obj.anonymise()¶
Once an object is anonymised a reference to that anonymisation will be recorded in PrivacyAnonymised.
obj.is_anonymised = BooleanField()¶
This is a boolean value stored in the database to register whether the object has been anonymised or not.
How anonymisation works¶
If a field is nullable, the value will be set to None (or in the case of
blankable strings, '').
If a field is not nullable, the value will be set to a sensible default:
- Numbers will be set to
0 - Strings will be set to a string representation of the primary key field
- Booleans will be set to
False(althoughBooleanField(null=True)will always be nullable) DateFieldandDateTimeFieldwill be set to the current date and timeTimeFieldwill be set to00:00DurationFieldwill be set totimedelta(0)EmailFieldwill be anonymised to{pk}@anon.example.comURLFieldwill be anonymised to{pk}@anon.example.comGenericIPAddressFieldwill be set to0.0.0.0UUIDFieldwill be set to{00000000-0000-0000-0000-000000000000}
These default actions can be overridden by defining a custom anonymiser as
anonymise_<field_name> method on the PrivacyMeta class - see the
PrivacyMeta documentation for more details.
Custom field types will also need a custom anonymiser to be defined.
Some fields cannot be anonymised unless they can be null, and trying to
anonymise them without a custom anonymiser will raise a
gdpr_assist.AnonymiseError exception:
- File fields (
FilePathField,FileField,ImageField) - Relationships (
OneToOneField,ForeignKey)
To ensure data integrity, trying to anonymise a ManyToManyField will always
raise a gdpr_assist.AnonymiseError, unless you are using a custom
anonymiser for that field.
The anonymiser cannot anonymise the primary key.