Splitting serializers. M2M Changes
I took the serializers and put them in their own file. I made the due dates be attached to the project with a foreign key, rather than M2M, better admin inline.
This commit is contained in:
parent
8bb12212e5
commit
588825332f
|
@ -1,3 +1,20 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from orderable.admin import OrderableAdmin
|
||||||
|
|
||||||
|
from project.models import Project, DueDate, Category
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
|
class DueDateInline(admin.TabularInline):
|
||||||
|
model = DueDate
|
||||||
|
|
||||||
|
class CategoryClass(OrderableAdmin):
|
||||||
|
list_display = ('__unicode__', 'sort_order_display')
|
||||||
|
|
||||||
|
class ProjectAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('title','description','status')
|
||||||
|
fields = ['title','description','status']
|
||||||
|
inlines = (DueDateInline,)
|
||||||
|
|
||||||
|
admin.site.register(Project, ProjectAdmin)
|
||||||
|
admin.site.register(DueDate)
|
||||||
|
admin.site.register(Category, CategoryClass)
|
1
project/api/__init__.py
Normal file
1
project/api/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
__author__ = 'tyrel'
|
18
project/api/serializers.py
Normal file
18
project/api/serializers.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
__author__ = 'tyrel'
|
||||||
|
from rest_framework import serializers
|
||||||
|
from project.models import Project, Category, DueDate
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
|
||||||
|
|
||||||
|
class CategorySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Category
|
||||||
|
|
||||||
|
|
||||||
|
class DueDateSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = DueDate
|
19
project/api/viewsets.py
Normal file
19
project/api/viewsets.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
__author__ = 'tyrel'
|
||||||
|
from rest_framework import viewsets
|
||||||
|
from project.models import Project, Category, DueDate
|
||||||
|
from project.api.serializers import ProjectSerializer, CategorySerializer, DueDateSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Project.objects.all()
|
||||||
|
serializer_class = ProjectSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class CategoryViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Category.objects.all()
|
||||||
|
serializer_class = CategorySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class DueDateViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = DueDate.objects.all()
|
||||||
|
serializer_class = DueDateSerializer
|
13
project/helpers.py
Normal file
13
project/helpers.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
__author__ = 'tyrel'
|
||||||
|
import datetime
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
def get_status(title, due_date):
|
||||||
|
overdue = ""
|
||||||
|
message = title
|
||||||
|
if due_date:
|
||||||
|
if due_date < datetime.date.today():
|
||||||
|
overdue = " Overdue"
|
||||||
|
message += " ({}{})".format(due_date.strftime(settings.DATE_FMT), overdue)
|
||||||
|
return message
|
||||||
|
|
|
@ -1,3 +1,52 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
import datetime
|
||||||
|
from django.conf import settings
|
||||||
|
from orderable.models import Orderable
|
||||||
|
|
||||||
# Create your models here.
|
STATUSES = (
|
||||||
|
(0, 'Upcoming'),
|
||||||
|
(1, 'Current'),
|
||||||
|
(2, 'Backlog'),
|
||||||
|
(3, 'Completed'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Project(models.Model):
|
||||||
|
title = models.CharField(max_length=256)
|
||||||
|
description = models.TextField(blank=True, null=True)
|
||||||
|
status = models.IntegerField(choices=STATUSES, default=0)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
|
||||||
|
class Category(Orderable):
|
||||||
|
title = models.CharField(max_length=256)
|
||||||
|
|
||||||
|
class Meta(Orderable.Meta):
|
||||||
|
verbose_name_plural = "Categories"
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
|
class DueDate(models.Model):
|
||||||
|
title = models.ForeignKey("Category")
|
||||||
|
due = models.DateField(blank=True, null=True)
|
||||||
|
completed = models.BooleanField(default=False)
|
||||||
|
project = models.ForeignKey("Project")
|
||||||
|
|
||||||
|
def completed_overdue_date(self):
|
||||||
|
if self.completed:
|
||||||
|
return "Completed"
|
||||||
|
if not self.due:
|
||||||
|
return ""
|
||||||
|
if self.due > datetime.date.today():
|
||||||
|
return "Overdue {}".format(self.due.strftime(settings.DATE_FMT))
|
||||||
|
return self.due.strftime(settings.DATE_FMT)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Due Date"
|
||||||
|
verbose_name_plural = "Due Dates"
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return unicode(self.title)
|
|
@ -2,4 +2,5 @@ Django==1.7.6
|
||||||
mysqlclient
|
mysqlclient
|
||||||
djangorestframework
|
djangorestframework
|
||||||
markdown
|
markdown
|
||||||
django-filter
|
django-filter
|
||||||
|
django-orderable
|
||||||
|
|
|
@ -15,9 +15,19 @@ INSTALLED_APPS = (
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles')
|
||||||
'rest_framework'
|
|
||||||
|
APPS = (
|
||||||
|
'project',
|
||||||
)
|
)
|
||||||
|
INSTALLED_APPS += APPS
|
||||||
|
|
||||||
|
|
||||||
|
THIRD_PARTY_APPS = (
|
||||||
|
'rest_framework',
|
||||||
|
'orderable'
|
||||||
|
)
|
||||||
|
INSTALLED_APPS += THIRD_PARTY_APPS
|
||||||
|
|
||||||
|
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE_CLASSES = (
|
||||||
|
@ -47,7 +57,7 @@ DATABASES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'en-us'
|
||||||
TIME_ZONE = 'EST'
|
TIME_ZONE = 'America/New_York'
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
USE_L10N = True
|
USE_L10N = True
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
@ -61,4 +71,6 @@ TEMPLATE_DIRS = (
|
||||||
os.path.join(BASE_DIR, 'templates'),
|
os.path.join(BASE_DIR, 'templates'),
|
||||||
)
|
)
|
||||||
|
|
||||||
from drf_settings import *
|
from drf_settings import *
|
||||||
|
|
||||||
|
DATE_FMT = "%a %m/%d"
|
|
@ -2,9 +2,13 @@ from django.conf.urls import patterns, include, url
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
from user_api_views import UserViewSet
|
from user_api_views import UserViewSet
|
||||||
|
from project.api.viewsets import ProjectViewSet, CategoryViewSet, DueDateViewSet
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'users', UserViewSet)
|
router.register(r'users', UserViewSet)
|
||||||
|
router.register(r'projects', ProjectViewSet)
|
||||||
|
router.register(r'categories', CategoryViewSet)
|
||||||
|
router.register(r'due_dates', DueDateViewSet)
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user