Hotfix for not being able to POST with changed 12 hour datetime format

This commit is contained in:
keannu125 2023-03-04 19:25:40 +08:00
parent df411d2f46
commit ec74dbdaf5
4 changed files with 45 additions and 1 deletions

Binary file not shown.

View file

@ -0,0 +1,21 @@
# Generated by Django 4.1.7 on 2023-03-04 11:06
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('notes', '0009_alter_note_content'),
]
operations = [
migrations.AlterField(
model_name='note',
name='owner',
field=models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View file

@ -0,0 +1,21 @@
# Generated by Django 4.1.7 on 2023-03-04 11:16
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('notes', '0010_alter_note_owner'),
]
operations = [
migrations.AlterField(
model_name='note',
name='owner',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View file

@ -4,8 +4,10 @@ from .models import Note
class NoteSerializer(serializers.HyperlinkedModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
date_created = serializers.DateTimeField(format="%d-%m-%Y %I:%M%p")
date_created = serializers.DateTimeField(
format="%d-%m-%Y %I:%M%p", read_only=True)
class Meta:
model = Note
fields = ('id', 'title', 'content', 'date_created', 'owner')
read_only_fields = ('id', 'date_created', 'owner')