Skip to content

Commit

Permalink
f/#61 Added BaseModel, BaseResource and inherited from them in models…
Browse files Browse the repository at this point in the history
….py and resources.py
  • Loading branch information
AndreiDuma committed Mar 24, 2013
1 parent 9acbd9c commit 41a850e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
13 changes: 8 additions & 5 deletions vmc_backend/api/resources.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
""" This file contains tastypie resources for all models in vmc_backend """
from tastypie import fields
from tastypie.resources import ModelResource, ALL
from tastypie.resources import ALL
from vmc_backend.core.base_resource import BaseResource
from vmc_backend.models import Assignment, Subject, Submission, UsersToSubjects
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization

class SubmissionResource(ModelResource):

class SubmissionResource(BaseResource):
student_id = fields.IntegerField(attribute='student_id')
assignment_id = fields.IntegerField(attribute='assignment_id')

Expand All @@ -19,7 +21,7 @@ class Meta:
authorization = Authorization()


class AssignmentResource(ModelResource):
class AssignmentResource(BaseResource):
subject_id = fields.IntegerField(attribute='subject_id')

class Meta:
Expand All @@ -33,14 +35,15 @@ class Meta:
def determine_format(self, request):
return 'application/json'

class SubjectResource(ModelResource):

class SubjectResource(BaseResource):

class Meta:
queryset = Subject.objects.all()
allowed_methods = ['get']


class UsersToSubjectsResource(ModelResource):
class UsersToSubjectsResource(BaseResource):
subject_id = fields.IntegerField(attribute='subject_id')
user_id = fields.IntegerField(attribute='user_id')

Expand Down
5 changes: 5 additions & 0 deletions vmc_backend/core/base_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.db import models

class BaseModel(models.Model):
class Meta:
abstract = True
4 changes: 4 additions & 0 deletions vmc_backend/core/base_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from tastypie.resources import ModelResource

class BaseResource(ModelResource):
pass
7 changes: 5 additions & 2 deletions vmc_backend/forms/subject_form.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class SubjectForm():
pass
from vmc_backend.core.base_model_form import BaseModelForm

class SubjectForm(BaseModelForm):

pass
11 changes: 6 additions & 5 deletions vmc_backend/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.db import models
from vmc_backend.core.base_model import BaseModel
from django.contrib.auth.models import User
from django.core.validators import MinLengthValidator


class Subject(models.Model):
class Subject(BaseModel):
""" Subject Model, referring to a course, for example.
Fields: name, description, link
Expand All @@ -30,7 +31,7 @@ def __str__(self):
return self.name


class Assignment(models.Model):
class Assignment(BaseModel):
subject = models.ForeignKey(Subject)
name = models.CharField(max_length=30)
text = models.TextField()
Expand All @@ -41,7 +42,7 @@ def __str__(self):
return self.name


class UsersToSubjects(models.Model):
class UsersToSubjects(BaseModel):
unique_together = ("subject_id", "user_id")
subject = models.ForeignKey(Subject)
user = models.ForeignKey(User)
Expand All @@ -59,7 +60,7 @@ def __str__(self):
return str(self.subject.pk) + "-" + str(self.user.pk)


class Submission(models.Model):
class Submission(BaseModel):
student = models.ForeignKey(User, related_name='submissions')
assignment = models.ForeignKey(Assignment, related_name='assignments')
# This is a timestamp
Expand All @@ -72,7 +73,7 @@ def __str__(self):
"-" + str(self.uploaded_at)


class SubmissionComment(models.Model):
class SubmissionComment(BaseModel):
submission = models.ForeignKey(Submission, related_name='comments')
filename = models.CharField(max_length=256, blank=True)
line_no = models.IntegerField(null=True, blank=True)
Expand Down

0 comments on commit 41a850e

Please sign in to comment.