initial drf project setup
This commit is contained in:
0
journal/__init__.py
Normal file
0
journal/__init__.py
Normal file
3
journal/admin.py
Normal file
3
journal/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
journal/apps.py
Normal file
6
journal/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class JournalConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'journal'
|
||||
24
journal/migrations/0001_initial.py
Normal file
24
journal/migrations/0001_initial.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 5.1.6 on 2025-03-02 13:33
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Post',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=255)),
|
||||
('content', models.TextField()),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('modified', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
journal/migrations/__init__.py
Normal file
0
journal/migrations/__init__.py
Normal file
13
journal/models.py
Normal file
13
journal/models.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Post(models.Model):
|
||||
title = models.CharField(max_length=255)
|
||||
content = models.TextField()
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title} ({self.content[0:255]}{"..." if len(self.content) > 255 else ""})"
|
||||
8
journal/serializers.py
Normal file
8
journal/serializers.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from rest_framework import serializers
|
||||
from journal.models import Post
|
||||
|
||||
|
||||
class PostSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Post
|
||||
fields = ["id", "title", "content", "created", "modified"]
|
||||
3
journal/tests.py
Normal file
3
journal/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
journal/views.py
Normal file
7
journal/views.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from rest_framework import viewsets
|
||||
from journal.models import Post
|
||||
from journal.serializers import PostSerializer
|
||||
|
||||
class PostViewSet(viewsets.ModelViewSet):
|
||||
queryset = Post.objects.all()
|
||||
serializer_class = PostSerializer
|
||||
Reference in New Issue
Block a user