Open
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.
Genarito
requested changes
Mar 6, 2026
| 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( |
Member
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
| def get_is_last_version(study: CGDSStudy) -> bool: | ||
| return study.version == study.get_last_version() | ||
|
|
||
| def to_representation(self, instance: CGDSStudy): |
| filter_horizontal = ('tissues',) | ||
|
|
||
| def tissue_list(self, obj): | ||
| return ', '.join(t.name for t in obj.tissues.all()) |
Member
There was a problem hiding this comment.
Optimizar a ', '.join(obj.tissues.values_list('name', flat=True))
| class UserFileSerializer(serializers.ModelSerializer): | ||
| user = UserSimpleSerializer(many=False, read_only=True) | ||
| survival_columns = SurvivalColumnsTupleUserFileSimpleSerializer(many=True, read_only=True) | ||
| tissue_ids = serializers.PrimaryKeyRelatedField( |
Member
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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