Skip to content

Instantly share code, notes, and snippets.

View Tobi-De's full-sized avatar
👁️‍🗨️
Trade-offs everywhere!

Tobi Tobi-De

👁️‍🗨️
Trade-offs everywhere!
View GitHub Profile
@Tobi-De
Tobi-De / forms.py
Created December 6, 2020 06:19
Cutomize django allauth signup form, from https://github.com/pydanny/multiple-user-types-django
from django import forms as d_forms
from allauth.account.forms import SignupForm
# SpyBookSignupForm inherits from django-allauth's SignupForm
class SpyBookSignupForm(SignupForm):
# Specify a choice field that matches the choice field on our user model
type = d_forms.ChoiceField(choices=[("SPY", "Spy"), ("DRIVER", "Driver")])
# Override the init method
@Tobi-De
Tobi-De / models.py
Created December 5, 2020 12:52
Multiple Users model using Proxy models, code originated from https://github.com/pydanny/multiple-user-types-django
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class User(AbstractUser):
class Types(models.TextChoices):
SPY = "SPY", "Spy"
DRIVER = "DRIVER", "Driver"

This is neither a guide nor a tutorial, but a list of django packages that are very well known and used in the community and which I have already used myself. I will update this list as I discover new packages. If you can't find a package in this list that matches your requirements, you can always head to the djangopackages website which has a list of most django packages. It's a bit like the official django packages website.

Packages I've tried and used inside my projects.

  • django-crispy-forms: If you are not a frontend pro like, this package will help you render your forms nicely with a little to no efforts, and it is very customisable. It comes with support for multiple frontend framework like bootstrap for example.
  • django-allauth: This package for me and many others is a must have if you need to handle users authentications and r

Through this guide we will see how to start a new django project using a cookiecutter, this guide is intended for beginners who already have experience with django, and who wants to know how to start a project following the best web standards. We will be using the cookiecutter-django, like it is said on the official github page, it is a framework for jumpstarting production-ready Django projects quickly.

what is cookiecutter ?

The cookiecutter project was initiated by https://github.com/audreyfeldroy, the co-author of the excellent Two Scoops of Django. It is a command-line utility that creates projects from cookiecutters (project templates). There are a multitude of cookiecutters for various frameworks, django, flask, etc ..., you can consult the list of cookiecutters avai

Modif

  • put the script right after the first place I talk about requirements
  • precise where some command are not needed when the user is using cookiecutter, for example to avoid using pip freeze.

In this post we are going to see how you can easily deploy your awesome Django project on a linux server( Virtual Private Server a.k.a vps ). In this tutorial I will be using DigitalOcean, a well know cloud provider that offers you a full control on your server, I also choose DigitalOcean because they have a 1-click app Dokku droplet to get you up and running quickly.

What is Dokku ?

from datetime import datetime
"""
Called during request:
process_request(request)
process_view(request, view_func, view_args, view_kwargs)
Called during response:
process_exception(request, exception) (only if the view raised an exception)
process_template_response(request, response) (only for template responses)
let connected = false;
const usernameInput = document.getElementById('username');
const button = document.getElementById('join_leave');
const container = document.getElementById('container');
const count = document.getElementById('count');
let room;
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
def async_mass_mailing(subject, message, from_mail, recipients_list, offset=0, limit=100):
if not recipients_list:
return
for email in recipients_list[offset:offset + limit]:
send_mail(subject, message, from_mail, [email])
async_task(
async_mass_mailing,
subject=subject,
message=message,
from_mail=from_mail,
@Tobi-De
Tobi-De / markdown.css
Last active October 9, 2020 14:12
Markdown CSS
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@Tobi-De
Tobi-De / models.py
Last active September 15, 2020 11:39
class Registration(TimeStampedModel):
....
tutor_m = models.ForeignKey(
"universities.Tutor",
on_delete=models.CASCADE,
)
....