Conversation
Introduce a new read-only tissues app (model, admin, serializer, views, URLs, app config) with initial migration and a data migration loading a list of tissue names. Add tissue ForeignKey fields to CGDSStudy and UserFile with corresponding migrations. Update serializers to accept tissue_id (writable PK) and include nested tissue representation on retrieve; persist tissue on updates/creates. Expose tissues in the REST API and enable filtering by tissue for CGDSStudy and UserFile (DjangoFilterBackend imports and filterset_fields). Register the app in settings and project URLs, and add a frontend URL constant for tissues. Admin/UI prevents adding/changing/deleting tissues (read-only).
Convert Tissue FK to ManyToMany on CGDSStudy and UserFile and update related code. Models updated to use tissues M2M; serializers changed (tissue_id -> tissue_ids, nested tissues in responses, create/update now set M2M relations); views' filterset_fields switched to 'tissues'; admin updated to filter and edit M2M with filter_horizontal and a user-facing tissue list column. Added migrations to replace FK with M2M for datasets_synchronization and user_files, and a new tissues migration that adds a unique code field and loads standardized initial tissue data (replacing the previous locale-specific seed). Run migrations after pulling these changes.
| version = serializers.IntegerField(read_only=True) | ||
| is_last_version = serializers.SerializerMethodField(method_name='get_is_last_version') | ||
| # tissue_ids: writable list of PKs; tissues: read-only nested list (set in to_representation) | ||
| tissue_ids = serializers.PrimaryKeyRelatedField( |
There was a problem hiding this comment.
Tanto esto como el to_representation debería ser eliminado. Acá poner directamente Tissues, el frontend debe recibir y enviar los IDs siempre. Si necesita saber cuál es cual, debe traer desde otro endpoint los Tissues y cargarlos en el select que corresponde. Pero esto de mandar todo el tiempo el mismo campo con diferente estructura es poco escalable: por cada FK que tengamos vamos a tener dos campos
There was a problem hiding this comment.
Eliminado el campo tissue_ids y el to_representation. El campo tissues queda manejado por DRF directamente como lista de IDs en lectura y escritura.
| def get_is_last_version(study: CGDSStudy) -> bool: | ||
| return study.version == study.get_last_version() | ||
|
|
||
| def to_representation(self, instance: CGDSStudy): |
There was a problem hiding this comment.
Eliminado junto con el comentario anteriorrr
src/user_files/admin.py
Outdated
| filter_horizontal = ('tissues',) | ||
|
|
||
| def tissue_list(self, obj): | ||
| return ', '.join(t.name for t in obj.tissues.all()) |
There was a problem hiding this comment.
Optimizar a ', '.join(obj.tissues.values_list('name', flat=True))
There was a problem hiding this comment.
Optimizado a values_list('name', flat=True)
src/user_files/serializers.py
Outdated
| class UserFileSerializer(serializers.ModelSerializer): | ||
| user = UserSimpleSerializer(many=False, read_only=True) | ||
| survival_columns = SurvivalColumnsTupleUserFileSimpleSerializer(many=True, read_only=True) | ||
| tissue_ids = serializers.PrimaryKeyRelatedField( |
There was a problem hiding this comment.
Idem comentario anterior, dejar siempre el campo tissues como IDs tanto para recibir como para enviar al frontend
There was a problem hiding this comment.
Idemmm, eliminado tissue_ids y la asignació en to_representation. tissues ahora siempre envía y recibe IDs
Tissue Support
Adds a new
tissuesDjango app providing read-only reference data for tissue types,and integrates it into
UserFileandCGDSStudyas a ManyToMany relationship.New app:
tissuesModel:
Tissuename(unique),code(unique) — code is the name uppercased with spacesreplaced by underscores (e.g.
Cervix Uteri→CERVIX_UTERI)delete()is overridden to raisePermissionDenied— tissues cannot be deletednameAdmin
has_add_permission,has_change_permissionandhas_delete_permissionall return
FalseInitial data (19 tissues)
Loaded via migration
0002_tissue_code_and_initial_data, sourced from GTEx tissue names:Adrenal Gland,Bladder,Blood,Brain,Breast,Cervix Uteri,Colon,Esophagus,Kidney,Liver,Lung,Ovary,Pancreas,Prostate,Skin,Stomach,Testis,Thyroid,UterusIntegration
UserFileandCGDSStudyboth have a newtissues = ManyToManyField(Tissue, blank=True)field. A file or study can have zero or more tissues assigned.
Serializers
tissues[{id, name, code}, ...]tissue_ids[1, 2, ...]Filters
Both list endpoints accept
?tissues=<id>as a query parameter (viaDjangoFilterBackend).Endpoints
GET/tissues/?search=GET/user-files/?tissues=<id>PATCH/user-files/<id>/{"tissue_ids": [1, 2]}GET/cgds/studies/?tissues=<id>PATCH/cgds/studies/<id>/{"tissue_ids": [1, 2]}Migrations
tissues0001_initialtissues_tissuetabletissues0002_tissue_code_and_initial_datacodefield, loads 19 tissuesuser_files0017_remove_userfile_tissue_userfile_tissuesdatasets_synchronization0038_remove_cgdsstudy_tissue_cgdsstudy_tissues