Once a model has been registered with gdpr-assist, its instances will have some additional attributes:
obj.anonymised = BooleanField()¶
This is a boolean value stored in the database to register whether the object has been anonymised or not.
Call this to anonymise the private fields on the object.
How anonymisation works¶
If a field is nullable, the value will be set to
None (or in the case of
If a field is not nullable, the value will be set to a sensible default:
- Numbers will be set to
- Strings will be set to a string representation of the primary key field
- Booleans will be set to
NullBooleanFieldwill always be nullable)
DateTimeFieldwill be set to the current date and time
TimeFieldwill be set to
DurationFieldwill be set to
EmailFieldwill be anonymised to
URLFieldwill be anonymised to
GenericIPAddressFieldwill be set to
UUIDFieldwill be set to
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
- File fields (
- Relationships (
To ensure data integrity, trying to anonymise a
ManyToManyField will always
gdpr_assist.AnonymiseError, unless you are using a custom
anonymiser for that field.
The anonymiser cannot anonymise the primary key.