Skip to content

Instantly share code, notes, and snippets.

View KabakiAntony's full-sized avatar

Kabaki Antony KabakiAntony

View GitHub Profile
@KabakiAntony
KabakiAntony / admin.py
Created October 29, 2022 13:00
root app admin file
from django.contrib import admin
class TonyOnlineAdmin(admin.AdminSite):
site_header = 'TonyOnline Administration'
site_title = 'TonyOnline Admin'
index_title = 'TonyOnline Admin'
site_url = None
tonyonline_admin_site = TonyOnlineAdmin(name='admin')
from .admin import tonyonline_admin_site
from django.urls import path
urlpatterns = [
path('admin/', tonyonline_admin_site.urls),
]
@KabakiAntony
KabakiAntony / models.py
Created October 29, 2022 14:55
this will be product app models file
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=100, unique=True)
description = models.TextField(max_length=255, blank=True)
def __str__(self):
return self.name
@KabakiAntony
KabakiAntony / products_admin.py
Created October 29, 2022 15:31
this will be products admin file
from django.contrib import admin
from tonyonline.admin import tonyonline_admin_site
from .models import Product, ProductImage, Category
tonyonline_admin_site.register(Product)
tonyonline_admin_site.register(ProductImage)
tonyonline_admin_site.register(Category)
@KabakiAntony
KabakiAntony / models.py
Created October 29, 2022 16:49
this should not be a new file but rather an update for models just want to highlight the category model update
class Category(models.Model):
name = models.CharField(max_length=100, unique=True)
description = models.TextField(max_length=255, blank=True)
def __str__(self):
return self.name
class Meta:
verbose_name_plural = "Categories"
@KabakiAntony
KabakiAntony / admin.py
Created October 29, 2022 17:27
custom productadmin class
class ProductAdmin(admin.ModelAdmin):
# define how the custom form is going to be rendered
list_display = ['name','description','category','price', 'stock', 'available', 'date']
# also make a change to this registration line
# by adding ProductAdmin to the register method
tonyonline_admin_site.register(Product, ProductAdmin)
@KabakiAntony
KabakiAntony / admin.py
Created October 29, 2022 18:04
updated admin file with filters now
from django.contrib import admin
from tonyonline.admin import tonyonline_admin_site
from .models import Product, ProductImage, Category
class ProductAdmin(admin.ModelAdmin):
# define how the custom form is going to be rendered
list_display = ['name','description','category','price', 'stock', 'available', 'date']
list_filter = ['category'] # add this line
@KabakiAntony
KabakiAntony / settings.py
Created October 30, 2022 17:09
make the following additional settings in the settings.py file
# add an import for os
import os
# note there will be other settings in this file
# in the templates setting there is a DIR LIST that is empty
# so just copy the below setting and replace the one there
'DIRS': [os.path.join(BASE_DIR, 'templates')],
@KabakiAntony
KabakiAntony / base.html
Created October 30, 2022 17:55
this will help you make some changes to the css
{% extends 'admin/base.html' %}
{% block extrastyle %}{{ block.super }}
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
:root {
--primary: #1fc55e;
--secondary: #4f9b6c;
--link-fg: #127438;
{% extends "admin/change_form.html" %}
{% block admin_change_form_document_ready %}
{{ block.super }}
<script type="text/javascript" charset="utf-8">
const productNameInput = document.querySelector('input[name=name]');
const productSlugInput = document.querySelector('input[name=slug]');
const slugify = (val) =>{
return val.toString().toLowerCase().trim()