Skip to content

Instantly share code, notes, and snippets.

View pmburu's full-sized avatar
🏠
Working from home

bV5hx0189 pmburu

🏠
Working from home
View GitHub Profile
from django.contrib.auth.base_user import BaseUserManager
class UserManager(BaseUserManager):
use_in_migrations = True
def _create_user(self, email, name, country, password, **extra_fields):
"""
Creates and saves a User with the given email and password.
"""
from django.urls import reverse
from django.db import models
from django.utils import timezone
from django.core.exceptions import ValidationError
# import datetime as dt
# from django.db.models.signals import pre_save, post_save, post_delete
import datetime
from wash_authentication.models import Client, Driver
MultipleObjectsReturned at /api/v1/bookings/booking/
get() returned more than one Driver -- it returned 3!
@pmburu
pmburu / drf_utils.py
Created May 3, 2020 00:45 — forked from twidi/drf_utils.py
Make Django Rest Framework correctly handle Django ValidationError raised in the save method of a model
"""
Sometimes in your Django model you want to raise a ``ValidationError`` in the ``save`` method, for
some reason.
This exception is not managed by Django Rest Framework because it occurs after its validation
process. So at the end, you'll have a 500.
Correcting this is as simple as overriding the exception handler, by converting the Django
``ValidationError`` to a DRF one.
"""
from django.core.exceptions import ValidationError as DjangoValidationError
@pmburu
pmburu / index.html
Created May 23, 2020 16:51
Wrong place to be - 404
<div class="o-404">
<h1 class="a-title">404</h1>
<p class="a-message">
You came to the wrong neighborhood
</p>
<div class="o-cat">
<div class="m-ears">
<div class="m-ear -right"></div>
<div class="m-ear -left"></div>
@pmburu
pmburu / urls.py
Last active August 27, 2020 10:25 — forked from iMerica/urls.py
Email verification in Django Rest Framework, Django All-Auth, Django Rest-Auth. Suitable for Single Page Applications
urlpatterns = [
url(r'^auth/registration/confirm-email/(?P<key>[-:\w]+)/$', ConfirmEmailView.as_view(), name='account_confirm_email'),
]
@pmburu
pmburu / audit_mixin.py
Created November 21, 2022 23:35 — forked from mjhea0/audit_mixin.py
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)