0% found this document useful (0 votes)
3 views4 pages

From Django

The document defines several Django models for a sales system, including HoaDon (invoice), ChiTietHoaDon (invoice details), NhanVien (employee), KhachHang (customer), SanPham (product), LoaiSanPham (product category), KhuyenMai (promotion), GiaVang (gold price), QuayBanHang (sales counter), and MuaLai (repurchase). Each model includes fields relevant to its purpose, such as primary keys, foreign keys, and various data types. The models also include string representations for easier identification.

Uploaded by

050903tth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

From Django

The document defines several Django models for a sales system, including HoaDon (invoice), ChiTietHoaDon (invoice details), NhanVien (employee), KhachHang (customer), SanPham (product), LoaiSanPham (product category), KhuyenMai (promotion), GiaVang (gold price), QuayBanHang (sales counter), and MuaLai (repurchase). Each model includes fields relevant to its purpose, such as primary keys, foreign keys, and various data types. The models also include string representations for easier identification.

Uploaded by

050903tth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

from django.

db import models

# Create your models here.

class HoaDon(models.Model):
ma_hoa_don = models.CharField(max_length=20, primary_key=True)
ngay_lap = models.DateTimeField()
tong_tien = models.DecimalField(max_digits=10, decimal_places=2)
ma_khach_hang = models.CharField(max_length=20)

def __str__(self):
return f'Hóa đơn {self.ma_hoa_don} - {self.ngay_lap}'

class ChiTietHoaDon(models.Model):
id = models.AutoField(primary_key=True)
ma_hoa_don = models.ForeignKey('HoaDon',
on_delete=models.CASCADE)
ma_san_pham = models.ForeignKey('SanPham',
on_delete=models.CASCADE)
so_luong = models.IntegerField()
don_gia = models.DecimalField(max_digits=10, decimal_places=2)

def __str__(self):
return f'Chi tiết hóa đơn {self.ma_hoa_don} - Sản phẩm
{self.ma_san_pham}'

class NhanVien(models.Model):
ma_nhan_vien = models.CharField(max_length=20, primary_key=True)
ho_ten = models.CharField(max_length=100)

def __str__(self):
return self.ho_ten

class KhachHang(models.Model):
ma_khach_hang = models.CharField(max_length=20, primary_key=True)
ho_ten = models.CharField(max_length=100)
sdt = models.CharField(max_length=15)

def __str__(self):
return self.ho_ten

class SanPham(models.Model):
ma_san_pham = models.CharField(max_length=20, primary_key=True)
ten_san_pham = models.CharField(max_length=100)
gia_ban = models.DecimalField(max_digits=10, decimal_places=2)
ton_kho = models.IntegerField()

def __str__(self):
return self.ten_san_pham

class LoaiSanPham(models.Model):
ma_loai_san_pham = models.CharField(max_length=20, primary_key=True)
ten_loai_san_pham = models.CharField(max_length=100)

def __str__(self):
return self.ten_loai_san_pham

class KhuyenMai(models.Model):
ma_khuyen_mai = models.CharField(max_length=20, primary_key=True)
ma_san_pham = models.ForeignKey('SanPham',
on_delete=models.CASCADE)
phan_tram_chiet_khau = models.DecimalField(max_digits=5,
decimal_places=2)
ngay_bat_dau = models.DateTimeField()
ngay_ket_thuc = models.DateTimeField()

def __str__(self):
return f'Khuyến mãi {self.ma_khuyen_mai} -
{self.ma_san_pham.ten_san_pham}'

class GiaVang(models.Model):
id = models.AutoField(primary_key=True)
thoi_gian = models.DateTimeField()
gia_vang_24k = models.DecimalField(max_digits=10, decimal_places=2)

def __str__(self):
return f'Giá vàng 24K tại {self.thoi_gian} - {self.gia_vang_24k} VND'

class QuayBanHang(models.Model):
ma_quay = models.CharField(max_length=20, primary_key=True)
ten_quay = models.CharField(max_length=100)

def __str__(self):
return self.ten_quay

class MuaLai(models.Model):
id = models.AutoField(primary_key=True)
ngay_mua_lai = models.DateTimeField()
gia_mua_lai = models.DecimalField(max_digits=10, decimal_places=2)
ghi_chu = models.TextField(null=True, blank=True)

hoa_don = models.ForeignKey('HoaDon', on_delete=models.CASCADE,


to_field='ma_hoa_don')
san_pham = models.ForeignKey('SanPham', on_delete=models.CASCADE,
to_field='ma_san_pham')

def __str__(self):
return f'Mua lại {self.id} cho Hóa đơn {self.hoa_don} - Sản phẩm
{self.san_pham}'

You might also like