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
11 changes: 11 additions & 0 deletions app/.gitIgnore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
venv
core/migrations
.env

__pycache__
app/__pycache__
core/__pycache__
./__pycache__
./__pycache__
utils/__pycache__
core/api_schema/__pycache__
52 changes: 45 additions & 7 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,36 @@
"""

from pathlib import Path
import os
from environ import Env
from datetime import timedelta

env = Env(
DEBUG=(bool, True)
)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# BASE_DIR = Path(__file__).resolve().parent.parent

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Env.read_env(os.path.join(BASE_DIR, '.env'))



# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-h-h69cr05lmc*w4vtkf+5qltg8#&#xf8fe(v9j9oxs-*-^#vjd'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

DEBUG = env("DEBUG")

SECRET_KEY = env('SECRET_KEY')

DB_PASSWORD = env('DB_PASSWORD')


ALLOWED_HOSTS = []

Expand All @@ -37,12 +54,16 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core'
'core',
'ninja_extra',
'ninja_jwt',
'corsheaders',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand Down Expand Up @@ -74,10 +95,20 @@
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases


# DATABASES = {
# 'default': Env.db_url_config(env('DATABASE_URL'))
# }


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'inventory',
'USER': 'postgres',
'PASSWORD': DB_PASSWORD,
'HOST': 'localhost',
'PORT': '5432',
}
}

Expand Down Expand Up @@ -123,4 +154,11 @@

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

AUTH_USER_MODEL = 'core.User'
AUTH_USER_MODEL = 'core.User'


NINJA_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=500),
'REFRESH_TOKEN_LIFETIME': timedelta(days=10),

}
23 changes: 8 additions & 15 deletions app/app/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
"""app URL Configuration.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/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 path
from django.urls import path, include
from core.api import api




urlpatterns = [
path('admin/', admin.site.urls),
path("", include("core.urls")),
path("api/", api.urls)

]
42 changes: 41 additions & 1 deletion app/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
"""Manage admin page for main app."""

# from django.contrib import admin
from django.contrib import admin
from .models import (
User, Category, Product, Order, Buyer, Seller
)

# Register your models here.


admin.site.site_header = "Inventory Manager Admin"
admin.site.site_title = "Drop it like its hot"
admin.site.index_title = "Inventory Manager"


class UsersAdmin(admin.ModelAdmin):
list_display = ["username", "role", "email", "phone_no", "first_name"]

admin.site.register(User, UsersAdmin)



class CategoryAdmin(admin.ModelAdmin):
list_display = ["title", "created_at"]

admin.site.register(Category, CategoryAdmin)


class ProductAdmin(admin.ModelAdmin):
list_display = ["category", "name", "description", "price","creator", "created_at"]

admin.site.register(Product, ProductAdmin)

class OrderAdmin(admin.ModelAdmin):
list_display = [
"buyer", "seller", "item", "paid",
"order_no", "delivered", "price", "completed"
]
admin.site.register(Order, OrderAdmin)


admin.site.register(Buyer)
admin.site.register(Seller)


Loading