Skip to content

Instantly share code, notes, and snippets.

View KabakiAntony's full-sized avatar

Kabaki Antony KabakiAntony

View GitHub Profile
@KabakiAntony
KabakiAntony / thread_subclass.py
Last active March 13, 2023 18:16
thread sub class
import time
from threading import Thread
class SimulateAPICallThread(Thread):
def __init__(self, name):
super().__init__()
self.name = name
def run(self):
@KabakiAntony
KabakiAntony / sample.py
Last active February 20, 2023 13:39
unit test example
import unittest
def sum(a, b):
return a + b
class TestSum(unittest.TestCase):
def test_sum_of_positive_numbers(self):
self.assertEqual(sum(2,2), 5)
@KabakiAntony
KabakiAntony / sample.py
Last active February 10, 2023 13:37
updated sample file with more tests for the sum function
import unittest
def sum(a, b):
return a + b
class TestSum(unittest.TestCase):
def test_sum_of_postive_numbers(self):
self.assertEqual(sum(2,2),4)
@KabakiAntony
KabakiAntony / models.py
Created February 7, 2023 02:28
final product models. py file
import uuid
import secrets
from django.db import models
from django.urls import reverse
from django.utils.text import slugify
class Category(models.Model):
title = models.CharField(max_length=200, unique=True)
description = models.TextField(max_length=255, blank=True)
@KabakiAntony
KabakiAntony / models.py
Last active February 7, 2023 02:22
image model
class Image(models.Model):
product_entry = models.ForeignKey(Product_Entry, on_delete=models.CASCADE)
thumb = models.ImageField(default='default.jpeg', blank=True)
def __str__(self):
return self.product_entry.title
class Meta:
verbose_name_plural = "Images"
@KabakiAntony
KabakiAntony / models.py
Created February 7, 2023 02:03
product entry model
class Product_Entry(models.Model):
sku = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(unique=True, max_length=200)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
size = models.ForeignKey(Size, on_delete=models.CASCADE, blank=True, null=True)
color = models.ForeignKey(Color, on_delete=models.CASCADE, blank=True, null=True)
quantity = models.PositiveIntegerField(default=1)
price = models.DecimalField(max_digits=12, decimal_places=2, default=0)
available = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
@KabakiAntony
KabakiAntony / models.py
Created February 7, 2023 02:00
size model
class Size(models.Model):
title = models.CharField(max_length=20)
def __str__(self):
return self.title
class Meta:
verbose_name_plural = "Sizes"
@KabakiAntony
KabakiAntony / models.py
Created February 7, 2023 01:52
color model
class Color(models.Model):
name = models.CharField(max_length=20, unique=True)
code = models.CharField(max_length=10, unique=True)
def __str__(self):
return self.name
class Meta:
verbose_name_plural = "Colors"
@KabakiAntony
KabakiAntony / models.py
Last active February 7, 2023 01:36
product model definition
import secrets
from django.db import models
from django.urls import reverse
from django.utils.text import slugify
class Product(models.Model):
title = models.CharField(max_length=200, unique=True)
slug = models.SlugField(unique=True, blank=True)
description = models.TextField()
@KabakiAntony
KabakiAntony / models.py
Created January 24, 2023 02:11
updated product model that creates a slug with a uuid string at the end
import secrets
from django.db import models
from django.utils.text import slugify
class Product(models.Model):
title = models.CharField(max_length=150, unique=True)
slug = models.SlugField(unique=True)
description = models.TextField(max_length=1000, blank=True)
def __str__(self):