Skip to content

wanisramdani/bookworm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TODO(important):

  • Move media folder from /build to its own path
  • Add author model

Tl;dr:


we can simplify the website to simply publication management where each post(article) is considered either


  • book
  • Pray-card
  • fatawi
  • video
  • audio

Article contains title, author, upload-date, category, klass, type and series as its fields

  • categories can be one of the following: book, Pray-card, fatawi, video or audio each category has its own unique fileds

  • klass is a custom model, klass can have many articles and article can have many klasses.

  • type is a custom model, article can have one type and type can have many articles

  • series is a custom model, article can be in one series and series can have many articles


File structure

Show don't tell


Database design

Article

{
    title: charfield(maxlength=500), Nullable=false
    author: chartfiled(maxlength=500), Nullable=false
    upload-date: Datefiled, Nullable=false
    category: Book, Cards..., Nullable=false
    Klass:  Klass , Nullable=false
    series: series, Nullable=true
    type:  type , Nullable=true
}

Category

{
    title: charfield(maxlength=500), Nullable=false
    slug: models.CharField(max_length=300)
    parent: models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True, related_name="children")
}

  • Books( {...article}, book-type, cover, pdfs, audio )
  • fatawi( {...article}, picture, content, pdf )
  • Pray-cards( {...article}, card-type, picture )
  • Audio( {...article}, mp3, session, album, duration, downloaded, played )
  • Video( {...article}, youtube-link )
  • klass(title)
  • series(title)

Setup the project environment


BACKEND


DATABASE:

# Install Postgres
sudo apt install postgresql

# Open Postgres, and create new super user
psql -U postgres
posgres=# CREATE USER alssahihin SUPERUSER PASSWORD 'stayAwayAlssahihin';

# Login with the new user and create database
alssahihin=# CREATE DATABASE alssahihin;


Create .env file in base diractory (~/PROJECT/.env):

Your .env file must contains the next variables (you can change the values):

DEBUG = True
DB_NAME = 'alssahihin'
DB_USERNAME = 'alssahihin'
DB_PASSWORD = 'stayAwayAlssahihin'
DB_HOST = ''

  • DEBUG: true : means we are in devolpement phase
  • DB_NAME = '' : database name
  • DB_USERNAME = '' : the username of the user we created before, we can use postgres but to keep our work clean we created a stand alone user
  • DB_PASSWORD = '' : user password
  • DB_HOST = '' : where you database hosted

Create admin

python manage.py createsuperuser


Creating an new app

When you create an new app(NEW_APP) you must:


  1. move it inside apps folder

  1. change the name in apps.py of the new created app to where the app is newly located (e.g: if you move the new app inside backend>apps, the variable name in NEW_APP/apps.py must be sth like backend.apps.APP_NAME)

  1. you should include the new app in INSTALLED_APPS in settings.py (e.g: backend.apps.NEW_APP.apps.NEW_APPConfig)

  1. create api folder inside ur NEW_APP and add init.py, serializers.py, urls.py and views folder or python file, depends on complex is gonna be.

  1. if you create views folder with multiple views u must import them in your views/init.py and use it as in one view file (to make importing it in urls easy)

NOTE: for each new folder you create on your own you must also create init.py inside of it ( e.g: NEW_FOLDER/init.py )


FRONTEND


npm install create-react-app

npm run build

If you want to test the react app alone run:

npm start

Common Errors:

  1. Makemigrations is mad!:

if django asks you to set a default value to some field when you try to makemigration after some changes on models you have to delete migartions folder and drop the table of that changed model. What causing this issue is django needs to add your new changes/fields to already created table in database and it has to set a value to those new added fields you can avoid that by adding default= attribute to you new fields.


Must run commands:

python3 manage.py collectstatic


Accounts(TODO):

  • Admin (permissions=Allow all)
  • Manager (permissions=restricted to the articles/site)
  • Visitor (permissions=read only)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published