Skip to content

hong539/image_board

Repository files navigation

image_board

To-do-list

  • reference implementation
  • app post:
    • How to render images/video Thumbnail?
    • edit views/PostDetail to make query for two models(Post/Comment) or even combine them into one to render template post_detail.html
      • ForeignKey.related_name
        • edit/checkt post_detail.html
        • To display the comments associated with the post, you can use the related_name attribute in the ForeignKey field of the Comment model. Here’s an example:
        • post is the Post object that we want to display comments for, and comments is the related_name that we defined in the ForeignKey field of the Comment model.
  • app accounts:
    • custom login/logged out page
    • user permission relations

Prerequisites

Quick Start

#spawns a virtual environment
poetry shell

#add packages
#src: https://python-poetry.org/docs/cli/#add
poetry add django
poetry add gunicorn
poetry add diagrams -G dev
poetry add django-environ==0.10.0

#remove packages
poetry remove diagrams
poetry remove django-environ

#for help
python3 manage.py help

#Creating a superuser for Django CMS system
python3 manage.py createsuperuser

#run devserver
python manage.py runserver 8080


#check gunicorn
gunicorn --version
#run with gunicorn
#some test codes in misc
gunicorn --workers=2 test_gunicorn01:app
#run with django project
#src: https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/gunicorn/
gunicorn locallibrary.wsgi


#Warning: You'll need to run these commands every time your models change in a way that will affect the structure of the data that needs to be stored (including both addition and removal of whole models and individual fields).
python3 manage.py makemigrations
python3 manage.py migrate

python3 manage.py sqlmigrate posts 0001

#run test
python3 manage.py test
#Showing more test information
python3 manage.py test --verbosity 2
#Speeding things up
python3 manage.py test --parallel auto
#Running specific tests
python3 manage.py test catalog.tests.test_models
python3 manage.py test catalog.tests.test_views
python3 manage.py test catalog.tests.test_forms

#deploy check
python3 manage.py check --deploy

#Starts the Python interactive interpreter
python3 manage.py shell

#src: https://docs.python.org/3.8/library/sys.html#sys.path
#A list of strings that specifies the search path for modules. 
#Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
python -c "import sys; print(sys.path)"

#add env PYTHONPATH
export PYTHONPATH=/path/to/your/module:$PYTHONPATH

#add packages by poetry
poetry add "psycopg[binary,pool]"
poetry add django-environ

#add packages by poetry to extras section
poetry add diagrams --optional --extras diagrams

#export requirements.txt if needed
poetry export -f requirements.txt --output requirements.txt
poetry export -f requirements.txt --output requirements.txt --without-hashes

Test

$ python manage.py shell
>>> from django.contrib.auth import get_user_model
>>> from myapp.models import BlogPost
>>> user = get_user_model().objects.create_user(username='testuser', password='12345')
>>> post = BlogPost.objects.create(author=user, date='2023-11-16', title='Test Post', post='This is a test post.')
>>> post.author.username
'testuser'

Misc

About

make a image board with Django

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published