Initial commit

This commit is contained in:
Keannu Christian Bernasol 2023-02-24 00:13:44 +08:00
commit 67bd8957d5
23 changed files with 849 additions and 0 deletions

View file

6
project/notes/admin.py Normal file
View file

@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Note
# Register your models here.
admin.site.register(Note)

6
project/notes/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class NotesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'notes'

View file

@ -0,0 +1,22 @@
# Generated by Django 4.1.7 on 2023-02-23 13:41
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Note',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=20)),
('content', models.TextField()),
],
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 4.1.7 on 2023-02-23 13:46
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('notes', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='note',
name='date_created',
field=models.DateTimeField(default=django.utils.timezone.now, editable=False),
),
]

View file

@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2023-02-23 14:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notes', '0002_note_date_created'),
]
operations = [
migrations.AlterField(
model_name='note',
name='content',
field=models.CharField(max_length=1024),
),
]

View file

12
project/notes/models.py Normal file
View file

@ -0,0 +1,12 @@
from django.db import models
from django.utils.timezone import now
# Create your models here.
class Note(models.Model):
title = models.CharField(max_length=20)
content = models.CharField(max_length=1024)
date_created = models.DateTimeField(default=now, editable=False)
def __str__(self):
return self.title

View file

@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Note
class NoteSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Note
fields = ('id', 'title', 'content')

3
project/notes/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

13
project/notes/urls.py Normal file
View file

@ -0,0 +1,13 @@
from django.urls import include, path
from rest_framework import routers
from . import views
router = routers.DefaultRouter()
router.register(r'notes', views.NoteViewSet)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path('', include(router.urls)),
]

9
project/notes/views.py Normal file
View file

@ -0,0 +1,9 @@
from django.shortcuts import render
from rest_framework import viewsets
from .serializers import NoteSerializer
from .models import Note
class NoteViewSet(viewsets.ModelViewSet):
queryset = Note.objects.all().order_by('date_created')
serializer_class = NoteSerializer