mirror of
https://github.com/lemeow125/Django-NotesApp.git
synced 2024-11-16 22:19:24 +08:00
Added logic to support public notes
This commit is contained in:
parent
53dc50c55a
commit
390040d460
7 changed files with 32 additions and 6 deletions
|
@ -26,9 +26,10 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = os.environ.get('SECRET_KEY')
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = False
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['lemeow125.github.io', 'keannu126.pythonanywhere.com']
|
||||
ALLOWED_HOSTS = ['lemeow125.github.io',
|
||||
'keannu126.pythonanywhere.com', '127.0.0.1', 'localhost']
|
||||
|
||||
|
||||
# Application definition
|
||||
|
|
Binary file not shown.
18
project/notes/migrations/0014_note_public.py
Normal file
18
project/notes/migrations/0014_note_public.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.1.7 on 2023-03-29 10:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('notes', '0013_remove_note_last_updated_note_date_created'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='note',
|
||||
name='public',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
|
@ -10,6 +10,7 @@ class Note(models.Model):
|
|||
content = models.TextField()
|
||||
date_created = models.DateTimeField(default=now, editable=False)
|
||||
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
public = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
|
|
@ -9,5 +9,5 @@ class NoteSerializer(serializers.HyperlinkedModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Note
|
||||
fields = ('id', 'title', 'content', 'date_created', 'owner')
|
||||
fields = ('id', 'title', 'content', 'date_created', 'owner', 'public')
|
||||
read_only_fields = ('id', 'date_created', 'owner')
|
||||
|
|
|
@ -9,5 +9,5 @@ router.register(r'notes', views.NoteViewSet)
|
|||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
|
||||
path('public_notes/', views.PublicNoteViewSet.as_view())
|
||||
]
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets
|
||||
from rest_framework import viewsets, generics
|
||||
from .serializers import NoteSerializer
|
||||
from .models import Note
|
||||
|
||||
|
||||
class NoteViewSet(viewsets.ModelViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = NoteSerializer
|
||||
queryset = Note.objects.all()
|
||||
|
||||
|
@ -16,3 +16,9 @@ class NoteViewSet(viewsets.ModelViewSet):
|
|||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(owner=self.request.user)
|
||||
|
||||
|
||||
class PublicNoteViewSet(generics.ListAPIView):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = NoteSerializer
|
||||
queryset = Note.objects.filter(public=True)
|
||||
|
|
Loading…
Reference in a new issue