Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
feat: Adds basic CRUD for categories
Browse files Browse the repository at this point in the history
Reolves #12
  • Loading branch information
oyeb committed Mar 28, 2020
1 parent 49fbda3 commit 1a28b21
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 0 deletions.
Empty file.
6 changes: 6 additions & 0 deletions hospitalco/categories/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin

from .models import Category

# Register your models here.
admin.site.register(Category)
24 changes: 24 additions & 0 deletions hospitalco/categories/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.0.3 on 2020-03-27 23:06

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=255)),
],
),
]
Empty file.
11 changes: 11 additions & 0 deletions hospitalco/categories/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import uuid

from django.db import models


# Create your models here.
class Category(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=255)
9 changes: 9 additions & 0 deletions hospitalco/categories/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import serializers

from .models import Category


class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ("id", "name")
3 changes: 3 additions & 0 deletions hospitalco/categories/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# from django.test import TestCase

# Create your tests here.
13 changes: 13 additions & 0 deletions hospitalco/categories/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.urls import include, path
from rest_framework.routers import DefaultRouter

from . import views

# Create a router and register our viewsets with it.
router = DefaultRouter()
router.register(r"", views.CategoryViewSet)

# The API URLs are now determined automatically by the router.
urlpatterns = [
path("", include(router.urls)),
]
12 changes: 12 additions & 0 deletions hospitalco/categories/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticatedOrReadOnly

from .models import Category
from .serializers import CategorySerializer


# Create your views here.
class CategoryViewSet(viewsets.ModelViewSet):
queryset = Category.objects.all()
serializer_class = CategorySerializer
permission_classes = [IsAuthenticatedOrReadOnly]

0 comments on commit 1a28b21

Please sign in to comment.