Skip to content

Instantly share code, notes, and snippets.

View jerinisready's full-sized avatar
💭
A catalyst of Change

JK jerinisready

💭
A catalyst of Change
View GitHub Profile
@jerinisready
jerinisready / django_orm_oscar_postgres_filter_options.py
Created May 20, 2021 19:16
Djagno ORM Oscar Postgres Product listing filtering search and sort views in drf!
@api_view()
def filter_options(request, pk):
""" pass parameters to create dynamic filter in frontend! """
attrs = ProductAttribute.objects.filter(
is_varying=True, product_class__id=pk
).prefetch_related('productattributevalue_set')
return Response({
'results': [{
'code': attr.code,
'label': attr.name,
@jerinisready
jerinisready / schedule_games.py
Created April 20, 2021 08:21
Here is how to schedule games between different teams. This scripts considers each team into "Grade A" or "Grade B". Games between "Group A" teams will have "event_weightage_score" of 100, Games between "Group B" teams will have "event_weightage_score" of 60, Games between teams from "Group A" and "Group B" will have "event_weightage_score" of 8…
import itertools
from datetime import date, timedelta
class Team:
grade = None
name = None
def __init__(self, name, grade):
self.name = name
@jerinisready
jerinisready / api_optimized_loading_for_django_oscar.py
Last active March 25, 2021 05:56
Django Oscar Product fetching (my personal) recommendation for API. This follows assumption that, Main screen Displays Parent / Standalone Products. Parent Products will have a dropdown from where, the card item can replace parent product with details of child product. This also devices into a logic that, Area of delivery is divided into differe…
from typing import Any, Union
from django.db.models import Q, QuerySet
from django.http import HttpRequest
from apps.api_set_v2.serializers.catalogue import ProductSimpleListSerializer
from apps.catalogue.models import Product
from apps.partner.models import StockRecord
@jerinisready
jerinisready / get_combinations.py
Last active March 17, 2021 14:09
Bit Wise Combinations of items in dictionary! If you have a set of objects, and want to access as a list of their combinations, use this simple snippet which uses bitwise and operator in python!
def get_status(code: int):
"""
This function will return a list of items
"""
_status_set = {
1: 'Alice',
2: 'Bob',
4: 'Charlie',
8: 'David',
@jerinisready
jerinisready / generate_dummy_comments.py
Created December 29, 2020 09:52
A simple script to generate Dummy Product Reviews in django oscar.
from faker import Faker
from random import randint, choice
from oscar.core.loading import get_model
from oscar.core.compat import get_user_model
from oscar.apps.catalogue.reviews.models import ProductReview, Vote
from oscar.apps.catalogue.models import Product
from apps.users.models import User
@jerinisready
jerinisready / calculate_percentage_of_2_fields_django_orm.py
Last active July 13, 2020 04:02
This is how I Implemented (pricedrop upto 40%) column in django oscar. Basically StockRecord model have 2 fields, 'price_excl_tax' and 'price_retail'. What we want is (price_excl_tax - price_retail) * 100 / price_excl_tax. We can use django's Expression wrapper to calculate the max offer price
"""
AUTHOR jerinisready
LICENSE : General Public License. Free to use, modify or publish unless u keep that open source.
This is how I implemented (pricedrop upto 40%) column in django oscar.
Basically StockRecord model have 2 fields, 'price_excl_tax' and 'price_retail'.
What we want is (price_retail - price_excl_tax) * 100 / price_retail.
We can use django's Expression wrapper to calculate the max offer price
@jerinisready
jerinisready / models.py
Created June 15, 2020 05:40
Dajngo Oscar Buy Now
from django.db import models
from oscar.apps.basket.abstract_models import AbstractBasket
from django.utils.translation import gettext_lazy as _
class Basket(AbstractBasket):
BUY_NOW, OPEN, MERGED, SAVED, FROZEN, SUBMITTED = (
"Buy Now", "Open", "Merged", "Saved", "Frozen", "Submitted")
STATUS_CHOICES = (
@jerinisready
jerinisready / __init__.py
Last active October 29, 2023 20:21
How to integrate Stripe payment in Django Oscar!
PAYMENT_EVENT_PURCHASE = 'Purchase'
PAYMENT_METHOD_STRIPE = 'Stripe'
STRIPE_EMAIL = 'stripeEmail'
STRIPE_TOKEN = 'stripeToken'
@jerinisready
jerinisready / intl-tel-input.html
Last active March 24, 2020 07:34
intl-tel-input.html
<input type='text' class="mobile-number" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/16.0.2/css/intlTelInput.css"
integrity="sha256-rTKxJIIHupH7lFo30458ner8uoSSRYciA0gttCkw1JE=" crossorigin="anonymous"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/16.0.2/js/utils.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/16.0.2/js/intlTelInput.js"></script>
<style>
.iti__flag {
@jerinisready
jerinisready / load-video-via-buffering.html
Created January 30, 2020 08:19
this is how to load a video via buffering Credits : Google Developrs at Medium :https://medium.com/google-developers/use-video-loops-with-interactive-canvas-dc7503e95c6a
<!doctype html>
<head>
<title> Canvas Draw </title>
</head>
<body>
<video id="can_video"></video>
</body>
<script>
/**