mirror of
https://github.com/lemeow125/Django-NotesApp.git
synced 2025-05-16 11:38:11 +08:00
Initial commit
This commit is contained in:
commit
67bd8957d5
23 changed files with 849 additions and 0 deletions
0
project/notes/__init__.py
Normal file
0
project/notes/__init__.py
Normal file
6
project/notes/admin.py
Normal file
6
project/notes/admin.py
Normal 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
6
project/notes/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class NotesConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'notes'
|
22
project/notes/migrations/0001_initial.py
Normal file
22
project/notes/migrations/0001_initial.py
Normal 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()),
|
||||
],
|
||||
),
|
||||
]
|
19
project/notes/migrations/0002_note_date_created.py
Normal file
19
project/notes/migrations/0002_note_date_created.py
Normal 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),
|
||||
),
|
||||
]
|
18
project/notes/migrations/0003_alter_note_content.py
Normal file
18
project/notes/migrations/0003_alter_note_content.py
Normal 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),
|
||||
),
|
||||
]
|
0
project/notes/migrations/__init__.py
Normal file
0
project/notes/migrations/__init__.py
Normal file
12
project/notes/models.py
Normal file
12
project/notes/models.py
Normal 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
|
8
project/notes/serializers.py
Normal file
8
project/notes/serializers.py
Normal 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
3
project/notes/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
13
project/notes/urls.py
Normal file
13
project/notes/urls.py
Normal 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
9
project/notes/views.py
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue