django-model-security-hardening

Applies encryption, audit logging, soft delete, and retention patterns to Django models storing PHI.

Updated May 11, 2026
One-click install
npx skills add https://github.com/thachrocky12345/local-agent-train-workstation --skill django-model-security-hardening-thachrocky12345
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django-model-security-hardening
Source: https://github.com/thachrocky12345/local-agent-train-workstation/tree/main/.claude/skills/django-model-security-hardening
Command: npx skills add https://github.com/thachrocky12345/local-agent-train-workstation --skill django-model-security-hardening-thachrocky12345

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires django-encrypted-model-fields, django-auditlog.

What problem does it solve? Django applications handling healthcare data often store PHI and PII in plaintext fields without audit trails, soft delete, or retention policies, creating HIPAA compliance gaps and security audit findings. ## Core Features & Use Cases - Field-Level Encryption: Migrate sensitive fields (tokens, clinical notes, NPI numbers) to EncryptedTextField or EncryptedCharField using django-encrypted-model-fields with a non-destructive backfill strategy. - Audit Logging & Soft Delete: Register Tier 1/Tier 2 models with django-auditlog and add a SoftDeleteMixin with ownership-filtered managers to prevent unfiltered PHI queries. - Retention & Signal Protections: Implement 7-year HIPAA retention commands with anonymization, plus pre_save sanitization of HTML clinical notes and crisis alerts on severe risk screenings. - Use Case: Before a production deployment of a telehealth backend, run the full hardening workflow to encrypt User OAuth tokens, register Notes and UserResponse for audit logging, and add deletion-logging signals across all PHI models. ## Quick Start Ask the AI to harden the Notes model by encrypting its fields and adding audit logging using the django-model-security-hardening skill.

Frequently Asked Questions about django-model-security-hardening

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I encrypt Django model fields for HIPAA compliance?

Use django-encrypted-model-fields to add EncryptedTextField or EncryptedCharField alongside existing plaintext fields, backfill data with a management command, then drop the plaintext column. Store the FIELD_ENCRYPTION_KEY in environment variables, never in code.

How to add audit logging to Django models with django-auditlog?

Install django-auditlog, add it to INSTALLED_APPS and middleware, then register models via auditlog.register() in a config module imported from AppConfig.ready(). You can exclude noisy fields like last_login or modified_at from tracking.

django-encrypted-model-fields vs django-fernet-fields for PHI?

Both provide Fernet-based field encryption for Django. This workflow recommends django-encrypted-model-fields, which offers EncryptedTextField and EncryptedCharField classes that integrate with standard migrations and a non-destructive backfill strategy.

Why do icontains lookups stop working after encrypting a Django field?

Encrypted fields store ciphertext in the database, so database-level string matching like __icontains and __startswith cannot work. Plan for this before encrypting searchable fields such as npi_number, or use a separate hashed lookup column.

How long must healthcare records be retained under HIPAA?

The workflow uses a 7-year minimum retention period for clinical notes, risk screenings, appointments, and payment records per state medical records laws. Records past retention should be anonymized rather than hard deleted, and minors' records may require longer retention.