Computer for Everybody

Django Model

Setting Database in settings.py

DATABASES = {
    "default": {
        "ENGINE": "mssql",
        "NAME": 'Fashion',
        'USER': 'sa',
        'PASSWORD': '123',
        'HOST': 'localhost',
        'PORT': 1433,
        'OPTIONS': {'driver': 'ODBC Driver 17 for SQL Server'}
    }
}

Create Model Category in models.py

from django.db import models
class Category(models.Model):
    CategoryId = models.SmallAutoField(primary_key = True)
    CategoryName = models.TextField(max_length = 128)
    class Meta:
        db_table = 'Category'

Import models

from .models import Category

Select all

Category.objects.all()

Select by id

Category.objects.filter(CategoryId = id).first()

Insert

cat = Category(CategoryName = 'Laptop')
cat.save()

Update

cat = Category.objects.filter(CategoryId = id).first()
cat.CategoryName = 'Mouse'
cat.save()

Delete

cat = Category.objects.filter(CategoryId = id).first()
cat.delete()