Third Party Monitoring Module
  • Third Party Monitoring Module Documentation
  • INTRODUCTION
    • Glossary / Terminology
    • FAQ
    • Releases / Changelog*
    • Report an Issue / Contact us
  • PRODUCT / END-USER DOCUMENTATION
    • Overview
      • User rights and permissions
    • Third Party Monitoring Module Navigation
    • Overall User Interface
    • Third Party Monitors section
      • List of Third Party Monitors
      • TPM partner details screen
    • List of Visits section
      • List of Visits
      • Visit details
      • Statuses and corresponding actions
        • Draft
        • Assigned
        • TPM Accepted
        • TPM Rejected
        • Cancelled
        • TPM Reported
        • Sent Back to TPM
        • UNICEF Approved
      • Emails notifications flow
    • TPM workflow
  • TECHNICAL DOCUMENTATION
    • Architecture
    • Development Setup
    • Deployment / DevOps
    • Backend Module structure
    • Data Model
    • Fixtures & management commands
    • API Documentation
      • Error Handling
    • Synchronization with VISION
    • Permissions framework
    • FSM Transitions conditions
    • FSM Transitions in view
    • API Metadata
    • Serializer Mixins
    • Model Mixins
    • Tests
    • Attachments
    • Email links & Tokens Authorization
    • Frontend
      • Module structure
      • Build process
      • Tests
Powered by GitBook
On this page
  1. TECHNICAL DOCUMENTATION

Attachments

We use attachments to store related documents for visit, activities, their reports and partner documents. This is a simple model which require file or hyperlink to be provided and has a simple generic foreign key, so it can be used everywhere.

The only interesting place here is the code field, which is used for generic relations to allow defining multiple reverse generic relations from one instance.

CodedGenericRelation

Simple generic relation is limited to one relation between models, because it just set content type and instance pk. So we can't make multiple reverse relations to one generic, just like this:

class MyModel(models.Model):
    attachments = GenericRelation(Attachment)
    report_attachments = GenericRelation(Attachment)

In this case both MyModel.attachments.all() and MyModel.report_attachments.all() will return identical set of attachments, because generic in fact don't create relation in the database. So we add code here, which will be used for filtering to separate attachments between defined relations.

class MyModel(models.Model):
    attachments = CodedGenericRelation(Attachment, code='attachments')
    report_attachments = CodedGenericRelation(Attachment, code='report_attachments')

Now, if we save attachment with code='attachments', it will appear only in MyModel.attachments.all(). report_attachments will be empty.

PreviousTestsNextEmail links & Tokens Authorization

Last updated 6 years ago