diff --git a/project/config/settings.py b/project/config/settings.py index eb769e6..30edc1c 100644 --- a/project/config/settings.py +++ b/project/config/settings.py @@ -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 diff --git a/project/db.sqlite3 b/project/db.sqlite3 index be67ebf..340949e 100644 Binary files a/project/db.sqlite3 and b/project/db.sqlite3 differ diff --git a/project/notes/migrations/0014_note_public.py b/project/notes/migrations/0014_note_public.py new file mode 100644 index 0000000..535c09c --- /dev/null +++ b/project/notes/migrations/0014_note_public.py @@ -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), + ), + ] diff --git a/project/notes/models.py b/project/notes/models.py index 82416b3..3ea6888 100644 --- a/project/notes/models.py +++ b/project/notes/models.py @@ -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 diff --git a/project/notes/serializers.py b/project/notes/serializers.py index b4189a4..ce97bbb 100644 --- a/project/notes/serializers.py +++ b/project/notes/serializers.py @@ -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') diff --git a/project/notes/urls.py b/project/notes/urls.py index dd22763..45b83d6 100644 --- a/project/notes/urls.py +++ b/project/notes/urls.py @@ -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()) ] diff --git a/project/notes/views.py b/project/notes/views.py index ee53847..4b475ff 100644 --- a/project/notes/views.py +++ b/project/notes/views.py @@ -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)