Add project information to experiment serializer fixes #205
This commit is contained in:
Родитель
5f58643305
Коммит
4e5726e025
|
@ -138,6 +138,13 @@ class Experiment(models.Model):
|
|||
def is_readonly(self):
|
||||
return self.status != self.STATUS_CREATED
|
||||
|
||||
@property
|
||||
def experiment_slug(self):
|
||||
return 'pref-flip-{project_slug}-{experiment_slug}'.format(
|
||||
project_slug=self.project.slug,
|
||||
experiment_slug=self.slug,
|
||||
)
|
||||
|
||||
|
||||
class ExperimentVariant(models.Model):
|
||||
experiment = models.ForeignKey(
|
||||
|
|
|
@ -34,6 +34,7 @@ class ExperimentVariantSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class ExperimentSerializer(serializers.ModelSerializer):
|
||||
project_name = serializers.ReadOnlyField(source='project.name')
|
||||
start_date = JSTimestampField()
|
||||
end_date = JSTimestampField()
|
||||
variant = ExperimentVariantSerializer()
|
||||
|
@ -42,8 +43,10 @@ class ExperimentSerializer(serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = Experiment
|
||||
fields = (
|
||||
'project_name',
|
||||
'name',
|
||||
'slug',
|
||||
'experiment_slug',
|
||||
'firefox_version',
|
||||
'firefox_channel',
|
||||
'objectives',
|
||||
|
|
|
@ -45,8 +45,10 @@ class TestExperimentSerializer(TestCase):
|
|||
experiment = ExperimentFactory.create_with_variants()
|
||||
serialized = ExperimentSerializer(experiment)
|
||||
self.assertEqual(serialized.data, {
|
||||
'project_name': experiment.project.name,
|
||||
'name': experiment.name,
|
||||
'slug': experiment.slug,
|
||||
'experiment_slug': experiment.experiment_slug,
|
||||
'firefox_version': experiment.firefox_version,
|
||||
'firefox_channel': experiment.firefox_channel,
|
||||
'objectives': experiment.objectives,
|
||||
|
|
Загрузка…
Ссылка в новой задаче