Commit 7af7880b by Bill DeRusha

Refactor 'value' models into shared abstract model

parent 3870cec7
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('course_metadata', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='expectedlearningitem',
options={},
),
migrations.AlterModelOptions(
name='syllabusitem',
options={},
),
]
...@@ -23,6 +23,17 @@ class AbstractNamedModel(TimeStampedModel): ...@@ -23,6 +23,17 @@ class AbstractNamedModel(TimeStampedModel):
abstract = True abstract = True
class AbstractValueModel(TimeStampedModel):
""" Abstract base class for models with only a value field. """
value = models.CharField(max_length=255)
def __str__(self):
return self.value
class Meta(object):
abstract = True
class AbstractMediaModel(TimeStampedModel): class AbstractMediaModel(TimeStampedModel):
""" Abstract base class for media-related (e.g. image, video) models. """ """ Abstract base class for media-related (e.g. image, video) models. """
src = models.URLField(max_length=255, unique=True) src = models.URLField(max_length=255, unique=True)
...@@ -58,18 +69,14 @@ class Prerequisite(AbstractNamedModel): ...@@ -58,18 +69,14 @@ class Prerequisite(AbstractNamedModel):
pass pass
class ExpectedLearningItem(TimeStampedModel): class ExpectedLearningItem(AbstractValueModel):
""" ExpectedLearningItem model. """ """ ExpectedLearningItem model. """
value = models.CharField(max_length=255) pass
def __str__(self):
return self.value
class SyllabusItem(TimeStampedModel): class SyllabusItem(AbstractValueModel):
""" SyllabusItem model. """ """ SyllabusItem model. """
parent = models.ForeignKey('self', blank=True, null=True, related_name='children') parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
value = models.CharField(max_length=255)
class Organization(TimeStampedModel): class Organization(TimeStampedModel):
......
...@@ -2,7 +2,7 @@ import ddt ...@@ -2,7 +2,7 @@ import ddt
from django.test import TestCase from django.test import TestCase
from course_discovery.apps.course_metadata.models import( from course_discovery.apps.course_metadata.models import(
AbstractNamedModel, AbstractMediaModel, CourseOrganization, ExpectedLearningItem AbstractNamedModel, AbstractMediaModel, AbstractValueModel, CourseOrganization
) )
from course_discovery.apps.course_metadata.tests import factories from course_discovery.apps.course_metadata.tests import factories
...@@ -124,12 +124,15 @@ class AbstractMediaModelTests(TestCase): ...@@ -124,12 +124,15 @@ class AbstractMediaModelTests(TestCase):
self.assertEqual(str(instance), src) self.assertEqual(str(instance), src)
class ExpectedLearningItemTests(TestCase): class AbstractValueModelTests(TestCase):
""" Tests for ExpectedLearningItem. """ """ Tests for AbstractValueModel. """
def test_str(self): def test_str(self):
""" Verify casting an instance to a string returns a string containing the value. """ """ Verify casting an instance to a string returns a string containing the value. """
value = 'Expected learnings' class TestAbstractValueModel(AbstractValueModel):
instance = ExpectedLearningItem(value=value) pass
value = 'abc'
instance = TestAbstractValueModel(value=value)
self.assertEqual(str(instance), value) self.assertEqual(str(instance), value)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment