Models Guide
This guide explains the key data models in ReversePilot and their relationships.
Core Models
Company Models
Company
Represents a company/organization using the system.
Key Fields:
- name: Company name
- company_type: Lender, broker, etc.
- ein: Employer Identification Number
- lei: Legal Entity Identifier
- fha_id: FHA ID for HECM loans
- mers_org_id: MERS Organization ID
User
Represents system users.
Key Fields:
- email: User email (unique)
- company: Foreign key to Company
- hierarchy: Super User, Company Administrator, Company User
- permission_groups: Many-to-many to PermissionGroup
- nmlsId: NMLS ID
- chumsId: CHUMS ID
Loan Models
Loan
Main loan application record.
Key Fields:
- status: Loan status (Prospect, Origination, Processing, etc.)
- uli: Universal Loan Identifier
- amount: Loan amount
- loanOfficer: Foreign key to User
- loanProduct: Foreign key to LoanProduct
- user: Foreign key to User (creator)
Status Choices: - Prospect - Origination - Processing - Underwriting - Clear to Close - Closing - Funding - Post Closing - Sold - Adversed - Withdrawn
LoanProduct
Loan product configuration.
Key Fields:
- name: Product name
- type: HECM, Proprietary, etc.
- company: Foreign key to Company
- default: Whether this is the default product
Borrower
Loan applicant information.
Key Fields:
- loan: Foreign key to Loan
- firstName, lastName: Name
- dob: Date of birth
- ssn: Social Security Number
- race, ethnicity, sex: HMDA data
Property
Subject property information.
Key Fields:
- loan: Foreign key to Loan
- address: Property address
- state: Property state
- propertyType: Property type
- appraisedValue: Appraised value
Fee
Loan fees and charges.
Key Fields:
- loan: Foreign key to Loan
- name: Fee name
- amount: Fee amount
- hudLine: HUD line number
- tolerance: GFE tolerance (0%, 10%, Unlimited)
- payee: Payee name
Document Models
DocumentTemplate
Document template definition.
Key Fields:
- name: Template name
- template_type: Template type
- is_active: Whether template is active
DocumentPackage
Collection of documents.
Key Fields:
- name: Package name
- templates: Many-to-many to DocumentTemplate
Model Relationships
Loan Relationships
Loan
├── Borrowers (1:N)
├── Property (1:1)
├── Fees (1:N)
├── CreditReports (1:N)
├── Documents (1:N)
├── Appraisals (1:N)
├── Titles (1:N)
└── LoanProduct (N:1)
Company Relationships
Company
├── Users (1:N)
├── LoanProducts (1:N)
├── Loans (1:N)
└── FeeTemplates (1:N)
Common Patterns
Soft Delete
Many models inherit from SoftDelete:
class SoftDelete(models.Model):
is_delete = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
class Meta:
abstract = True
Historical Records
Models use simple_history for audit trails:
history = HistoricalRecords()
Base Loan Model
Loan-related models inherit from BaseLoanModel:
class BaseLoanModel(SoftDelete):
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
history = HistoricalRecords(inherit=True)
class Meta:
abstract = True
Model Methods
Loan Methods
get_youngest_borrower(): Get youngest borrowerget_calculated_loan(): Get loan calculation resultsget_principal_limit(): Calculate principal limitget_imip_fee(): Calculate IMIP fee
Borrower Methods
get_full_name(): Get full nameget_age(): Calculate age
Property Methods
get_address_line_1(): Get address line 1get_full_address(): Get complete address
Query Patterns
Filtering
# Active loans
loans = Loan.objects.filter(is_delete=False)
# Loans by status
loans = Loan.objects.filter(status=Loan.LoanStatusChoices.PROCESSING)
# Loans by company
loans = Loan.objects.filter(user__company=company)
Related Objects
# Get borrowers for a loan
borrowers = loan.borrowers.all()
# Get fees for a loan
fees = loan.fees.all()
# Get credit reports for a borrower
credit_reports = borrower.credit_reports.all()
Best Practices
- Use Related Names: Define clear related names
- Index Fields: Index frequently queried fields
- Validate Data: Use model validation
- Handle Relationships: Properly handle foreign keys
- Soft Delete: Use soft delete for data retention
Next Steps
- Services Guide - Service layer patterns
- Testing Guide - Testing models
- Architecture - System architecture
For model questions, refer to the code or contact the development team.