From 0d44b6c7aff15bb277bd749887d0ea5449758a2f Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 3 Jun 2016 20:17:22 +0200 Subject: [PATCH] Add Payment and Refund models and admin --- refunding/__init__.py | 0 refunding/admin.py | 18 ++++++++++ refunding/apps.py | 5 +++ refunding/migrations/0001_initial.py | 51 ++++++++++++++++++++++++++++ refunding/migrations/__init__.py | 0 refunding/models.py | 33 ++++++++++++++++++ refunding/tests.py | 3 ++ refunding/views.py | 3 ++ refunds/settings.py | 1 + 9 files changed, 114 insertions(+) create mode 100644 refunding/__init__.py create mode 100644 refunding/admin.py create mode 100644 refunding/apps.py create mode 100644 refunding/migrations/0001_initial.py create mode 100644 refunding/migrations/__init__.py create mode 100644 refunding/models.py create mode 100644 refunding/tests.py create mode 100644 refunding/views.py diff --git a/refunding/__init__.py b/refunding/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/refunding/admin.py b/refunding/admin.py new file mode 100644 index 0000000..f2fb438 --- /dev/null +++ b/refunding/admin.py @@ -0,0 +1,18 @@ +from django.contrib import admin +from refunding.models import Refund, Payment + + +@admin.register(Refund) +class RefundAdmin(admin.ModelAdmin): + list_display = ('title', 'date', 'user') + list_display_links = ('title',) + search_fields = ('title',) + date_hierarchy = 'date' + + +@admin.register(Payment) +class PaymentAdmin(admin.ModelAdmin): + list_display = ('title', 'date', 'value', 'user', 'refund') + list_display_links = ('title',) + search_fields = ('title',) + date_hierarchy = 'date' diff --git a/refunding/apps.py b/refunding/apps.py new file mode 100644 index 0000000..3d6db18 --- /dev/null +++ b/refunding/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class RefundingConfig(AppConfig): + name = 'refunding' diff --git a/refunding/migrations/0001_initial.py b/refunding/migrations/0001_initial.py new file mode 100644 index 0000000..b0b2bc6 --- /dev/null +++ b/refunding/migrations/0001_initial.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-03 18:18 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Payment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=100)), + ('date', models.DateField()), + ('value', models.IntegerField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='Refund', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=100)), + ('date', models.DateField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.AddField( + model_name='payment', + name='refund', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='refunding.Refund'), + ), + migrations.AddField( + model_name='payment', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/refunding/migrations/__init__.py b/refunding/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/refunding/models.py b/refunding/models.py new file mode 100644 index 0000000..aa85635 --- /dev/null +++ b/refunding/models.py @@ -0,0 +1,33 @@ +from django.db import models +from django.conf import settings + +AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') + + +class Refund(models.Model): + title = models.CharField(max_length=100) + date = models.DateField() + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + user = models.ForeignKey( + AUTH_USER_MODEL, + on_delete=models.PROTECT + ) + + +class Payment(models.Model): + title = models.CharField(max_length=100) + date = models.DateField() + value = models.IntegerField() + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + user = models.ForeignKey( + AUTH_USER_MODEL, + on_delete=models.PROTECT + ) + refund = models.ForeignKey( + Refund, + on_delete=models.SET_NULL, + null=True, + blank=True + ) diff --git a/refunding/tests.py b/refunding/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/refunding/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/refunding/views.py b/refunding/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/refunding/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/refunds/settings.py b/refunds/settings.py index 5b1c84c..8db70ae 100644 --- a/refunds/settings.py +++ b/refunds/settings.py @@ -48,6 +48,7 @@ X_FRAME_OPTIONS = 'DENY' # Application definition INSTALLED_APPS = [ + 'refunding', 'authentication', 'crispy_forms', 'django.contrib.admin',