diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 6f8f59b..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.pyc -*.db -*.sqlite3 diff --git a/blogging/__pycache__/__init__.cpython-39.pyc b/blogging/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..d8e73f9 Binary files /dev/null and b/blogging/__pycache__/__init__.cpython-39.pyc differ diff --git a/blogging/__pycache__/admin.cpython-39.pyc b/blogging/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000..d01999b Binary files /dev/null and b/blogging/__pycache__/admin.cpython-39.pyc differ diff --git a/blogging/__pycache__/apps.cpython-39.pyc b/blogging/__pycache__/apps.cpython-39.pyc new file mode 100644 index 0000000..62cd420 Binary files /dev/null and b/blogging/__pycache__/apps.cpython-39.pyc differ diff --git a/blogging/__pycache__/models.cpython-39.pyc b/blogging/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000..0af53d0 Binary files /dev/null and b/blogging/__pycache__/models.cpython-39.pyc differ diff --git a/blogging/__pycache__/tests.cpython-39.pyc b/blogging/__pycache__/tests.cpython-39.pyc new file mode 100644 index 0000000..37eff0e Binary files /dev/null and b/blogging/__pycache__/tests.cpython-39.pyc differ diff --git a/blogging/__pycache__/urls.cpython-39.pyc b/blogging/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..58fe017 Binary files /dev/null and b/blogging/__pycache__/urls.cpython-39.pyc differ diff --git a/blogging/__pycache__/views.cpython-39.pyc b/blogging/__pycache__/views.cpython-39.pyc new file mode 100644 index 0000000..766b077 Binary files /dev/null and b/blogging/__pycache__/views.cpython-39.pyc differ diff --git a/blogging/admin.py b/blogging/admin.py index 1175916..d51e404 100644 --- a/blogging/admin.py +++ b/blogging/admin.py @@ -1,6 +1,11 @@ from django.contrib import admin -from blogging.models import Post, Category +from .models import Post, Category +class PostAdmin(admin.ModelAdmin): + prepopulated_fields = {'title':('text',)} -admin.site.register(Post) -admin.site.register(Category) +class CatagoryAdmin(admin.ModelAdmin): + prepopulated_fields = {'name':('description',)} + +admin.site.register(Post, PostAdmin) +admin.site.register(Category, CatagoryAdmin) diff --git a/blogging/fixtures/blogging_test_fixture.json b/blogging/fixtures/blogging_test_fixture.json index bf5269e..d85425f 100644 --- a/blogging/fixtures/blogging_test_fixture.json +++ b/blogging/fixtures/blogging_test_fixture.json @@ -35,4 +35,4 @@ "date_joined": "2013-05-24T05:35:58.628Z" } } -] +] \ No newline at end of file diff --git a/blogging/migrations/0001_initial.py b/blogging/migrations/0001_initial.py index 5d406bf..c783614 100644 --- a/blogging/migrations/0001_initial.py +++ b/blogging/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.1 on 2019-10-29 01:39 +# Generated by Django 2.1.1 on 2021-06-30 23:44 from django.conf import settings from django.db import migrations, models diff --git a/blogging/migrations/0002_category.py b/blogging/migrations/0002_category.py index 0ccbe19..19cf067 100644 --- a/blogging/migrations/0002_category.py +++ b/blogging/migrations/0002_category.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.1 on 2019-11-05 03:35 +# Generated by Django 2.1.1 on 2021-07-09 22:32 from django.db import migrations, models @@ -18,5 +18,8 @@ class Migration(migrations.Migration): ('description', models.TextField(blank=True)), ('posts', models.ManyToManyField(blank=True, related_name='categories', to='blogging.Post')), ], + options={ + 'verbose_name_plural': 'Categories', + }, ), ] diff --git a/blogging/migrations/0003_auto_20191104_1942.py b/blogging/migrations/0003_remove_category_posts.py similarity index 50% rename from blogging/migrations/0003_auto_20191104_1942.py rename to blogging/migrations/0003_remove_category_posts.py index 663c56d..ae14874 100644 --- a/blogging/migrations/0003_auto_20191104_1942.py +++ b/blogging/migrations/0003_remove_category_posts.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.1 on 2019-11-05 03:42 +# Generated by Django 2.1.1 on 2021-08-11 00:28 from django.db import migrations @@ -10,8 +10,8 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AlterModelOptions( - name='category', - options={'verbose_name_plural': 'Categories'}, + migrations.RemoveField( + model_name='category', + name='posts', ), ] diff --git a/blogging/migrations/__pycache__/0001_initial.cpython-39.pyc b/blogging/migrations/__pycache__/0001_initial.cpython-39.pyc new file mode 100644 index 0000000..c383c0c Binary files /dev/null and b/blogging/migrations/__pycache__/0001_initial.cpython-39.pyc differ diff --git a/blogging/migrations/__pycache__/0002_category.cpython-39.pyc b/blogging/migrations/__pycache__/0002_category.cpython-39.pyc new file mode 100644 index 0000000..ffbe588 Binary files /dev/null and b/blogging/migrations/__pycache__/0002_category.cpython-39.pyc differ diff --git a/blogging/migrations/__pycache__/0003_remove_category_posts.cpython-39.pyc b/blogging/migrations/__pycache__/0003_remove_category_posts.cpython-39.pyc new file mode 100644 index 0000000..47b9685 Binary files /dev/null and b/blogging/migrations/__pycache__/0003_remove_category_posts.cpython-39.pyc differ diff --git a/blogging/migrations/__pycache__/__init__.cpython-39.pyc b/blogging/migrations/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..e0f926b Binary files /dev/null and b/blogging/migrations/__pycache__/__init__.cpython-39.pyc differ diff --git a/blogging/models.py b/blogging/models.py index 10d6cc3..f8d311f 100644 --- a/blogging/models.py +++ b/blogging/models.py @@ -1,3 +1,6 @@ +# blogging/models.py + +from django.contrib import admin from django.db import models from django.contrib.auth.models import User @@ -15,7 +18,6 @@ def __str__(self): class Category(models.Model): name = models.CharField(max_length=128) description = models.TextField(blank=True) - posts = models.ManyToManyField(Post, blank=True, related_name='categories') class Meta: verbose_name_plural = 'Categories' diff --git a/blogging/static/django_blog.css b/blogging/static/django_blog.css index 45a882d..64560dc 100644 --- a/blogging/static/django_blog.css +++ b/blogging/static/django_blog.css @@ -71,4 +71,4 @@ ul.categories { } ul.categories li { display: inline; -} +} \ No newline at end of file diff --git a/blogging/templates/blogging/detail.html b/blogging/templates/blogging/detail.html index ea5b9c8..1658f91 100644 --- a/blogging/templates/blogging/detail.html +++ b/blogging/templates/blogging/detail.html @@ -1,5 +1,4 @@ {% extends "base.html" %} - {% block content %} Home

{{ post }}

@@ -14,4 +13,4 @@

{{ post }}

  • {{ category }}
  • {% endfor %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/blogging/templates/blogging/list.html b/blogging/templates/blogging/list.html index d8aa919..49993a4 100644 --- a/blogging/templates/blogging/list.html +++ b/blogging/templates/blogging/list.html @@ -3,7 +3,7 @@

    Recent Posts

    {% comment %} here is where the query happens {% endcomment %} {% for post in posts %}
    -

    +

    {{ post }}

    @@ -19,4 +19,4 @@

    {% endfor %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/blogging/tests.py b/blogging/tests.py index 4250226..968254c 100644 --- a/blogging/tests.py +++ b/blogging/tests.py @@ -1,12 +1,8 @@ import datetime - +from django.utils.timezone import utc from django.test import TestCase from django.contrib.auth.models import User -from django.utils.timezone import utc - -from blogging.models import Post -from blogging.models import Category - +from blogging.models import Post, Category class PostTestCase(TestCase): fixtures = ['blogging_test_fixture.json', ] @@ -20,7 +16,6 @@ def test_string_representation(self): actual = str(p1) self.assertEqual(expected, actual) - class CategoryTestCase(TestCase): def test_string_representation(self): @@ -29,7 +24,6 @@ def test_string_representation(self): actual = str(c1) self.assertEqual(expected, actual) - class FrontEndTestCase(TestCase): """test views provided in the front-end""" fixtures = ['blogging_test_fixture.json', ] @@ -69,4 +63,4 @@ def test_details_only_published(self): self.assertEqual(resp.status_code, 200) self.assertContains(resp, title) else: - self.assertEqual(resp.status_code, 404) + self.assertEqual(resp.status_code, 404) \ No newline at end of file diff --git a/blogging/urls.py b/blogging/urls.py index 172a39c..f5bdfb9 100644 --- a/blogging/urls.py +++ b/blogging/urls.py @@ -1,7 +1,7 @@ from django.urls import path -from blogging.views import list_view, detail_view +from blogging.views import stub_view, list_view, detail_view urlpatterns = [ path('', list_view, name="blog_index"), path('posts//', detail_view, name="blog_detail"), -] +] \ No newline at end of file diff --git a/blogging/views.py b/blogging/views.py index b4bab4f..b60220d 100644 --- a/blogging/views.py +++ b/blogging/views.py @@ -1,9 +1,23 @@ from django.shortcuts import render from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.template import loader - from blogging.models import Post +def stub_view(request, *args, **kwargs): + body = "Stub View\n\n" + if args: + body += "Args:\n" + body += "\n".join(["\t%s" % a for a in args]) + if kwargs: + body += "Kwargs:\n" + body += "\n".join(["\t%s: %s" % i for i in kwargs.items()]) + return HttpResponse(body, content_type="text/plain") + +def list_view(request): + published = Post.objects.exclude(published_date__exact=None) + posts = published.order_by('-published_date') + context = {'posts': posts} + return render(request, 'blogging/list.html', context) def detail_view(request, post_id): published = Post.objects.exclude(published_date__exact=None) @@ -13,10 +27,4 @@ def detail_view(request, post_id): raise Http404 context = {'post': post} return render(request, 'blogging/detail.html', context) - - -def list_view(request): - published = Post.objects.exclude(published_date__exact=None) - posts = published.order_by('-published_date') - context = {'posts': posts} - return render(request, 'blogging/list.html', context) + \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..678d6df Binary files /dev/null and b/db.sqlite3 differ diff --git a/mysite/__pycache__/__init__.cpython-39.pyc b/mysite/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..41ef1e7 Binary files /dev/null and b/mysite/__pycache__/__init__.cpython-39.pyc differ diff --git a/mysite/__pycache__/settings.cpython-39.pyc b/mysite/__pycache__/settings.cpython-39.pyc new file mode 100644 index 0000000..fc9b2ee Binary files /dev/null and b/mysite/__pycache__/settings.cpython-39.pyc differ diff --git a/mysite/__pycache__/urls.cpython-39.pyc b/mysite/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..08a0372 Binary files /dev/null and b/mysite/__pycache__/urls.cpython-39.pyc differ diff --git a/mysite/__pycache__/wsgi.cpython-39.pyc b/mysite/__pycache__/wsgi.cpython-39.pyc new file mode 100644 index 0000000..e3e9d76 Binary files /dev/null and b/mysite/__pycache__/wsgi.cpython-39.pyc differ diff --git a/mysite/settings.py b/mysite/settings.py index 14e4a11..0535a59 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -1,3 +1,4 @@ +# mysite/settings.py """ Django settings for mysite project. @@ -20,7 +21,7 @@ # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'xak=ca*e6hvh8q5hgfz5l9ees)_pxjif0)ui!ikifg4!enjk+7' +SECRET_KEY = '0@3oddlht7%xzs2$)izd7e(kod(-+esmnr!z(ia*7+f$u11j4-' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -39,6 +40,13 @@ 'django.contrib.staticfiles', 'polling', 'blogging', + + 'django.contrib.sites', + + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'allauth.socialaccount.providers.facebook', ] MIDDLEWARE = [ @@ -56,7 +64,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'mysite/templates')], + 'DIRS': [],#os.path.join(BASE_DIR, 'mysite/templates')], # <- Make DIRS look like this 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -101,6 +109,13 @@ }, ] +AUTHENTICATION_BACKENDS = [ + # Needed to login by username in Django admin, regardless of `allauth` + 'django.contrib.auth.backends.ModelBackend', + + # `allauth` specific authentication methods, such as login by e-mail + 'allauth.account.auth_backends.AuthenticationBackend', +] # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ @@ -120,6 +135,8 @@ # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' - LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/' +SITE_ID = 1 + +LOGIN_REDIRECT_URL = '/profile/' \ No newline at end of file diff --git a/mysite/templates/base.html b/mysite/templates/base.html index 4bb0230..f39f257 100644 --- a/mysite/templates/base.html +++ b/mysite/templates/base.html @@ -1,3 +1,4 @@ +{# mysite/templates/base.html #} {% load staticfiles %} @@ -24,4 +25,4 @@ - + \ No newline at end of file diff --git a/mysite/templates/login.html b/mysite/templates/login.html index 1566d0f..e1a56ee 100644 --- a/mysite/templates/login.html +++ b/mysite/templates/login.html @@ -6,4 +6,4 @@

    My Blog Login

    {{ form.as_p }}

    -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/mysite/urls.py b/mysite/urls.py index 446cd8f..96b41b5 100644 --- a/mysite/urls.py +++ b/mysite/urls.py @@ -1,3 +1,4 @@ +# mysite/urls.py """mysite URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: @@ -13,15 +14,17 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + + from django.contrib import admin -from django.urls import path, include +from django.urls import path, include # <-- Make sure you have both of these imports. from django.contrib.auth.views import LoginView, LogoutView - urlpatterns = [ path('', include('blogging.urls')), - path('polling/', include('polling.urls')), - path('admin/', admin.site.urls), + path('polling/', include('polling.urls')), # <-- Add this + path('admin/', admin.site.urls), # <- already there path('login/', LoginView.as_view(template_name='login.html'), name="login"), path('logout/', LogoutView.as_view(next_page='/'), name="logout"), -] + path('accounts/', include('allauth.urls')), +] \ No newline at end of file diff --git a/polling/__pycache__/__init__.cpython-39.pyc b/polling/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..ee000fd Binary files /dev/null and b/polling/__pycache__/__init__.cpython-39.pyc differ diff --git a/polling/__pycache__/admin.cpython-39.pyc b/polling/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000..824be02 Binary files /dev/null and b/polling/__pycache__/admin.cpython-39.pyc differ diff --git a/polling/__pycache__/apps.cpython-39.pyc b/polling/__pycache__/apps.cpython-39.pyc new file mode 100644 index 0000000..565d301 Binary files /dev/null and b/polling/__pycache__/apps.cpython-39.pyc differ diff --git a/polling/__pycache__/models.cpython-39.pyc b/polling/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000..6dad65b Binary files /dev/null and b/polling/__pycache__/models.cpython-39.pyc differ diff --git a/polling/__pycache__/urls.cpython-39.pyc b/polling/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..d7f7022 Binary files /dev/null and b/polling/__pycache__/urls.cpython-39.pyc differ diff --git a/polling/__pycache__/views.cpython-39.pyc b/polling/__pycache__/views.cpython-39.pyc new file mode 100644 index 0000000..8a049d4 Binary files /dev/null and b/polling/__pycache__/views.cpython-39.pyc differ diff --git a/polling/admin.py b/polling/admin.py index 15a1f46..52bd86e 100644 --- a/polling/admin.py +++ b/polling/admin.py @@ -1,4 +1,4 @@ from django.contrib import admin from polling.models import Poll -admin.site.register(Poll) +admin.site.register(Poll) \ No newline at end of file diff --git a/polling/migrations/0001_initial.py b/polling/migrations/0001_initial.py index 2be60e7..7b23ae9 100644 --- a/polling/migrations/0001_initial.py +++ b/polling/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.1 on 2019-10-29 01:24 +# Generated by Django 2.1.1 on 2021-06-30 22:56 from django.db import migrations, models diff --git a/polling/migrations/__pycache__/0001_initial.cpython-39.pyc b/polling/migrations/__pycache__/0001_initial.cpython-39.pyc new file mode 100644 index 0000000..fb9c2f4 Binary files /dev/null and b/polling/migrations/__pycache__/0001_initial.cpython-39.pyc differ diff --git a/polling/migrations/__pycache__/__init__.cpython-39.pyc b/polling/migrations/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..cadf835 Binary files /dev/null and b/polling/migrations/__pycache__/__init__.cpython-39.pyc differ diff --git a/polling/models.py b/polling/models.py index 6a940d2..1467d04 100644 --- a/polling/models.py +++ b/polling/models.py @@ -1,3 +1,4 @@ +# blogging/models.py from django.db import models class Poll(models.Model): @@ -6,4 +7,4 @@ class Poll(models.Model): score = models.IntegerField(default=0) def __str__(self): - return self.title + return self.title \ No newline at end of file diff --git a/polling/templates/polling/detail.html b/polling/templates/polling/detail.html index bb18db0..744b29c 100644 --- a/polling/templates/polling/detail.html +++ b/polling/templates/polling/detail.html @@ -16,4 +16,4 @@

    {{ poll.title }}

    -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/polling/templates/polling/list.html b/polling/templates/polling/list.html index 9cf4282..73b6747 100644 --- a/polling/templates/polling/list.html +++ b/polling/templates/polling/list.html @@ -1,3 +1,4 @@ +{# polling/templates/polling/list.html #} {% extends "base.html" %} {% block content %}

    Polls

    @@ -8,4 +9,4 @@

    {% endfor %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/polling/urls.py b/polling/urls.py index 9c4e2fd..6ef0686 100644 --- a/polling/urls.py +++ b/polling/urls.py @@ -1,7 +1,9 @@ +# polling/urls.py + from django.urls import path from polling.views import list_view, detail_view urlpatterns = [ path('', list_view, name="poll_index"), path('polls//', detail_view, name="poll_detail"), -] +] \ No newline at end of file diff --git a/polling/views.py b/polling/views.py index 6339808..ec672cf 100644 --- a/polling/views.py +++ b/polling/views.py @@ -1,3 +1,5 @@ +# polling/views.py + from django.shortcuts import render from django.http import Http404 from polling.models import Poll @@ -20,4 +22,4 @@ def detail_view(request, poll_id): poll.save() context = {'poll': poll} - return render(request, 'polling/detail.html', context) + return render(request, 'polling/detail.html', context) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 81580ab..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -Django==2.1.1 -pytz==2019.3 diff --git a/tutorial/manage.py b/tutorial/manage.py new file mode 100644 index 0000000..07a69d9 --- /dev/null +++ b/tutorial/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/tutorial/quickstart/__init__.py b/tutorial/quickstart/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tutorial/quickstart/admin.py b/tutorial/quickstart/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/tutorial/quickstart/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/tutorial/quickstart/apps.py b/tutorial/quickstart/apps.py new file mode 100644 index 0000000..98ec0c9 --- /dev/null +++ b/tutorial/quickstart/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class QuickstartConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'quickstart' diff --git a/tutorial/quickstart/migrations/__init__.py b/tutorial/quickstart/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tutorial/quickstart/models.py b/tutorial/quickstart/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/tutorial/quickstart/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/tutorial/quickstart/serializers.py b/tutorial/quickstart/serializers.py new file mode 100644 index 0000000..695f76b --- /dev/null +++ b/tutorial/quickstart/serializers.py @@ -0,0 +1,14 @@ +from django.contrib.auth.models import User, Group +from rest_framework import serializers + + +class UserSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = User + fields = ['url', 'username', 'email', 'groups'] + + +class GroupSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Group + fields = ['url', 'name'] \ No newline at end of file diff --git a/tutorial/quickstart/tests.py b/tutorial/quickstart/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/tutorial/quickstart/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/tutorial/quickstart/views.py b/tutorial/quickstart/views.py new file mode 100644 index 0000000..3764924 --- /dev/null +++ b/tutorial/quickstart/views.py @@ -0,0 +1,25 @@ +from django.shortcuts import render + +# Create your views here. +from django.contrib.auth.models import User, Group +from rest_framework import viewsets +from rest_framework import permissions +from tutorial.quickstart.serializers import UserSerializer, GroupSerializer + + +class UserViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows users to be viewed or edited. + """ + queryset = User.objects.all().order_by('-date_joined') + serializer_class = UserSerializer + permission_classes = [permissions.IsAuthenticated] + + +class GroupViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows groups to be viewed or edited. + """ + queryset = Group.objects.all() + serializer_class = GroupSerializer + permission_classes = [permissions.IsAuthenticated] \ No newline at end of file diff --git a/tutorial/tutorial/__init__.py b/tutorial/tutorial/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tutorial/tutorial/asgi.py b/tutorial/tutorial/asgi.py new file mode 100644 index 0000000..bb7e5c8 --- /dev/null +++ b/tutorial/tutorial/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for tutorial project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings') + +application = get_asgi_application() diff --git a/tutorial/tutorial/settings.py b/tutorial/tutorial/settings.py new file mode 100644 index 0000000..ff36051 --- /dev/null +++ b/tutorial/tutorial/settings.py @@ -0,0 +1,131 @@ +""" +Django settings for tutorial project. + +Generated by 'django-admin startproject' using Django 3.2.6. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-b&$y003z_h!@v)6tpm%r+do1---2kkagmky5t0#d4e_s&-xfh=' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'rest_framework', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'tutorial.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'tutorial.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +REST_FRAMEWORK = { + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'PAGE_SIZE': 10 +} diff --git a/tutorial/tutorial/urls.py b/tutorial/tutorial/urls.py new file mode 100644 index 0000000..e931261 --- /dev/null +++ b/tutorial/tutorial/urls.py @@ -0,0 +1,32 @@ +"""tutorial URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import include, path +from rest_framework import routers +from tutorial.quickstart import views + +router = routers.DefaultRouter() +router.register(r'users', views.UserViewSet) +router.register(r'groups', views.GroupViewSet) + +# Wire up our API using automatic URL routing. +# Additionally, we include login URLs for the browsable API. +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include(router.urls)), + path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) + +] diff --git a/tutorial/tutorial/wsgi.py b/tutorial/tutorial/wsgi.py new file mode 100644 index 0000000..3d57e0c --- /dev/null +++ b/tutorial/tutorial/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for tutorial project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings') + +application = get_wsgi_application()