This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .admin import tonyonline_admin_site | |
from django.urls import path | |
urlpatterns = [ | |
path('admin/', tonyonline_admin_site.urls), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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')], | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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() |
OlderNewer