Skip to content

Commit

Permalink
improve sample queryset and serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
atarkowska committed Nov 13, 2017
1 parent 2884f44 commit 3778fc7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 29 deletions.
1 change: 0 additions & 1 deletion emgapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ def available(self, request):
'latitude': "CAST(latitude as DECIMAL(10,5))"
}
) \
.annotate(runs_count=Count('runs')) \
.prefetch_related(
Prefetch('studies', queryset=_qs2),
Prefetch('biome', queryset=Biome.objects.all()),
Expand Down
33 changes: 7 additions & 26 deletions emgapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,34 +635,15 @@ def get_studies(self, obj):
def get_runs(self, obj):
return None

# counters
runs_count = serializers.IntegerField()

class Meta:
model = emg_models.Sample
fields = (
'url',
'runs_count',
'accession',
'biosample',
'analysis_completed',
'collection_date',
'geo_loc_name',
'longitude',
'latitude',
'sample_desc',
'environment_biome',
'environment_feature',
'environment_material',
'sample_name',
'sample_alias',
'host_tax_id',
'species',
'last_update',
'biome',
'studies',
'runs',
'sample_metadata'
exclude = (
'primary_accession',
'is_public',
'metadata_received',
'sequencedata_received',
'sequencedata_archived',
'submission_account_id',
)


Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_list(self, live_server, runs, api_version):
study.bioproject,
sample.accession,
sample.biome.biome_name,
sample.runs_count,
run.accession,
run.experiment_type,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_details(self, client, sample):
assert rsp['data']['type'] == "samples"
assert rsp['data']['id'] == "ERS01234"
_attr = rsp['data']['attributes']
assert(len(_attr) == 18)
assert(len(_attr) == 17)
assert _attr['accession'] == "ERS01234"
assert _attr['biosample'] == "SAMS01234"
assert _attr['sample-desc'] == "abcdefghijklmnoprstuvwyz"
Expand Down

0 comments on commit 3778fc7

Please sign in to comment.