Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions code/austin/django/lab07/pokedex-main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
13 changes: 13 additions & 0 deletions code/austin/django/lab07/pokedex-main/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
django = "*"
djangorestframework = "*"

[requires]
python_version = "3.8"
60 changes: 60 additions & 0 deletions code/austin/django/lab07/pokedex-main/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions code/austin/django/lab07/pokedex-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Pokedex Starter

## Installation

Make sure you have Python and Pipenv installed on your computer.

Download the repo and save it to your code folder in the class repo. *make sure you download it, don't clone it or it won't upload to the class repo correctly*

If you are not running Python 3.8, edit the last line of the `Pipfile` to refer to your version instead.

Navigate to the pokedex folder in the terminal and do the following:

- `pipenv install` Create the virtual enviroment and install dependencies.
- `pipenv shell` Enter the new virtual enviroment.
- `python manage.py migrate users` Migrate the user model. *this django project uses a custom user model, you MUST migrate the users app before migrating the rest!*
- `python manage.py migrate` Migrate all other models.
- `python manage.py createsuperuser` Create yourself a super user.
- `python manage.py load_pokemon` Load Pokemon into the database.

You're good to go! This Django project comes with a database full of Pokemon, login/logout/registration pages, and a `home.html` template for you to create your Vue app.
21 changes: 13 additions & 8 deletions code/austin/django/lab07/pokedex-main/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from users.models import CustomUser
from rest_framework import serializers
from django.contrib.auth import get_user_model
from pokemon import models
from pokemon.models import Pokemon, Type

class NestedPokemonSerializer(serializers.ModelSerializer):
class Meta:
model = models.Pokemon
model = Pokemon

fields = ('id', 'name')

class NestedTypeSerializer(serializers.ModelSerializer):
class Meta:
model = models.Type
model = Type

fields = ('id', 'type')

class NestedUserSerializer(serializers.ModelSerializer):
Expand All @@ -22,18 +24,21 @@ class PokemonSerializer(serializers.ModelSerializer):
type_detail = NestedTypeSerializer(read_only = True, many = True, source = 'types')
caught_by_user = NestedUserSerializer(read_only = True, many = True, source = 'caught_by')
class Meta:
model = models.Pokemon
fields = ('id','name','type_detail', 'height', 'weight', 'image_front', 'image_back', 'caught_by_user')
model = Pokemon
fields = ('id','name','type_detail', 'height', 'weight', 'image_front', 'image_back', 'caught_by_user', 'caught_by')



class TypeSerializer(serializers.ModelSerializer):
pokemon_detail = NestedPokemonSerializer(read_only = True, many = True, source = 'pokemon')
class Meta:
model = models.Type
model = Type
fields = ('id','type', 'pokemon', 'pokemon_detail')

class UserSerializer(serializers.ModelSerializer):
class Meta:
model = CustomUser
fields = ('id','username','date_joined', 'caught')
fields = ('id', 'username', 'date_joined', 'caught')



10 changes: 8 additions & 2 deletions code/austin/django/lab07/pokedex-main/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from django.urls import path

from .views import PokemonViewSet, TypeViewSet, CurrentUserView, UserViewSet

from .views import CurrentPokemonView, PokemonViewSet, TypeViewSet, CurrentUserView, UserViewSet

from rest_framework.routers import DefaultRouter


router = DefaultRouter()
router.register('pokemon',PokemonViewSet, basename='pokemon')
router.register('type',TypeViewSet, basename='type')
router.register('users',UserViewSet, basename='users')
urlpatterns = router.urls

urlpatterns = router.urls + [
path('currentuser/', CurrentUserView.as_view())
]


""" urlpatterns = [
path('', ListPokemon.as_view()),
Expand Down
6 changes: 6 additions & 0 deletions code/austin/django/lab07/pokedex-main/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class CurrentUserView(generics.RetrieveAPIView):
def get_object(self):
return self.request.user

class CurrentPokemonView(generics.RetrieveAPIView):
serializer_class = PokemonSerializer
def get_object(self):
return self.request.user


""" class ListPokemon(generics.ListCreateAPIView):
queryset = models.Pokemon.objects.all()
serializer_class = PokemonSerializer
Expand Down
22 changes: 22 additions & 0 deletions code/austin/django/lab07/pokedex-main/manage.py
Original file line number Diff line number Diff line change
@@ -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', 'pokedex_project.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()
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
path('admin/', admin.site.urls),
path('users/', include('django.contrib.auth.urls')),
path('users/', include('users.urls')),
path('', TemplateView.as_view(template_name='home.html'), name='home'),
path('', include('pokemon.urls')),

path('api/v1/', include('api.urls')),
]
Loading