fishfin
fishfin

Reputation: 279

Linked tables/models in Django - more than Foreign Keys

I am designing a Django project, where I need the following (I want to implement something more complex, but simplified here):

Table: work_order
Columns: owner_id,
         ...,
         contract_file_id (maps to 'all_files.id')

Table: labour_license
Columns: owner_id,
         ...,
         license_file_id (maps to 'all_files.id')

Table: all_files
Columns: id (UUID4Field),
         category (CharField,
                  'contract' if linked to 'work_order.contract_file_id',
                  'labour_lic' if linked to 'labour_license.license_file_id')
         file (FileField)
         ...

I have literally 10s of file fields like this, and I would like to write some kind of Mixin or custom Field, or even a metaclass if required, which I can use for all such file fields. If it is possible, would appreciate some ideas or directions I can look into.

Upvotes: 0

Views: 27

Answers (0)

Related Questions