Commit 9970fe92 by Bill DeRusha Committed by Clinton Blackburn

Add Currency to core app

parent a9ffdd1e
......@@ -5,26 +5,30 @@ from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _
from course_discovery.apps.core.forms import UserThrottleRateForm
from course_discovery.apps.core.models import User, UserThrottleRate
from course_discovery.apps.core.models import User, UserThrottleRate, Currency
@admin.register(User)
class CustomUserAdmin(UserAdmin):
""" Admin configuration for the custom User model. """
list_display = ('username', 'email', 'full_name', 'first_name', 'last_name', 'is_staff')
fieldsets = (
(None, {'fields': ('username', 'password')}),
(_('Personal info'), {'fields': ('full_name', 'first_name', 'last_name', 'email')}),
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
'groups', 'user_permissions')}),
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
)
@admin.register(UserThrottleRate)
class UserThrottleRateAdmin(admin.ModelAdmin):
""" Admin configuration for the UserThrottleRate model. """
form = UserThrottleRateForm
raw_id_fields = ('user',)
admin.site.register(User, CustomUserAdmin)
admin.site.register(UserThrottleRate, UserThrottleRateAdmin)
@admin.register(Currency)
class CurrencyAdmin(admin.ModelAdmin):
list_display = ('code', 'name',)
ordering = ('code', 'name',)
search_fields = ('code', 'name',)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0003_auto_20160315_1910'),
]
operations = [
migrations.CreateModel(
name='Currency',
fields=[
('code', models.CharField(unique=True, primary_key=True, serialize=False, max_length=6)),
('name', models.CharField(max_length=255)),
],
options={
'verbose_name_plural': 'Currencies',
},
),
]
......@@ -37,3 +37,15 @@ class UserThrottleRate(models.Model):
'The rate of requests to limit this user to. The format is specified by Django'
' Rest Framework (see http://www.django-rest-framework.org/api-guide/throttling/).')
)
class Currency(models.Model):
""" Table of currencies as defined by ISO-4217. """
code = models.CharField(max_length=6, primary_key=True, unique=True)
name = models.CharField(max_length=255)
def __str__(self):
return '{code} - {name}'.format(code=self.code, name=self.name)
class Meta(object):
verbose_name_plural = 'Currencies'
......@@ -4,7 +4,7 @@ from django.test import TestCase
from django_dynamic_fixture import G
from social.apps.django_app.default.models import UserSocialAuth
from course_discovery.apps.core.models import User
from course_discovery.apps.core.models import User, Currency
# pylint: disable=no-member
......@@ -38,3 +38,15 @@ class UserTests(TestCase):
user = G(User, full_name=full_name, first_name=first_name, last_name=last_name)
self.assertEqual(user.get_full_name(), full_name)
class CurrencyTests(TestCase):
""" Tests for the Currency class. """
def test_str(self):
""" Verify casting an instance to a string returns a string containing the ID and name of the currency. """
code = 'USD',
name = 'U.S. Dollar'
instance = Currency(code=code, name=name)
self.assertEqual(str(instance), '{code} - {name}'.format(code=code, name=name))
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