Breaking News

New Updates

Shoping Website project

Shoping Website project

Shopingapp--> Models.py

from django.db import models

# Create your models here.
class Category(models.Model):
    name = models.CharField(max_length=250, unique=True)
    slug = models.SlugField(max_length=250, unique=True)
    desc = models.TextField(blank=True)
    image = models.ImageField(upload_to='category', blank=True)

    class Meta:
        ordering = ('name',)
        verbose_name = 'category'
        verbose_name_plural = 'categories'

    def __str__(self):
        return '{}'.format(self.name)

class Product(models.Model):
    name = models.CharField(max_length=250, unique=True)
    slug = models.SlugField(max_length=250, unique=True)
    desc = models.TextField(blank=True)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    image = models.ImageField(upload_to='product', blank=True)
    stock= models.IntegerField()
    available = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now=True)
    update = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('name',)
        verbose_name = 'product'
        verbose_name_plural = 'products'

    def __str__(self):
        return '{}'.format(self.name)


go to shopingapp --> admin.py

from django.contrib import admin

# Register your models here.
from . models import Category, Product

class CatogoryAdmin(admin.ModelAdmin):
    list_display = ['name','slug']
    prepopulated_fields = {'slug':('name',)}
admin.site.register(Category,CatogoryAdmin)

class ProductAdmin(admin.ModelAdmin):
    list_display = ['name','price','stock','available','created','update']
    list_editable = ['price','stock','available']
    prepopulated_fields = {'slug':('name',)}
    list_per_page = 20
admin.site.register(Product, ProductAdmin)


go to templates --> base.html

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
  <meta name="description" content="{% block metadescription %}{% endblock %}">
    <title>{% block title %}{% endblock %}</title>
</head>
<body>
<div>
  {% include 'header.html' %}
  {% include 'navbar.html' %}
  {% block content %}
  {% endblock %}
</div>
{% include 'footer.html' %}
</body>
</html>


Create static folder name ‘static’ on project folder.

Add logo.png and banner.png on static folder.

go to templates --> header.html

{% load static %}
<header>
    <center>
        <img src="{% static 'img/logo.png' %}" alt="LogImagage">
    </center>
</header>


Go to Templates --> nav.html

No comments