Skip to content

Instantly share code, notes, and snippets.

View Mexarm's full-sized avatar
🎯
Focusing

Armando H Mexarm

🎯
Focusing
  • Mexico
View GitHub Profile
@Mexarm
Mexarm / forms.py
Created June 16, 2022 03:05 — forked from maraujop/forms.py
django-crispy-forms bootstrap form example
# -*- coding: utf-8 -*-
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
class MessageForm(forms.Form):
text_input = forms.CharField()
@dsample
dsample / .editorconfig
Last active May 9, 2021 20:29
Some files which I usually include within a repo's 'first commit'
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
indent_style = space
indent_size = 2
@cansadadeserfeliz
cansadadeserfeliz / admin.py
Last active March 10, 2022 12:13
Django: validate inline form in main form
from django.contrib import admin
from product.forms import EquipmentForm
@admin.register(Equipment)
class EquipmentAdmin(admin.ModelAdmin):
form = EquipmentForm
inlines = [
EquipmentGalleryInline,
@joshkehn
joshkehn / forms.py
Created June 26, 2013 17:35
Ingredient ModelForm (Django)
from django import forms
from menu.models import Ingredient, Diet, FoodPreference
class IngredientForm (forms.ModelForm):
class Meta:
model = Ingredient
exclude = ["franchise"]
def __init__ (self, *args, **kwargs):
brand = kwargs.pop("brand")
@mindlace
mindlace / middleware.py
Created October 19, 2012 13:43
Add user created/modified to every model
"""Add user created_by and modified_by foreign key refs to any model automatically.
Almost entirely taken from https://github.com/Atomidata/django-audit-log/blob/master/audit_log/middleware.py"""
from django.db.models import signals
from django.utils.functional import curry
class WhodidMiddleware(object):
def process_request(self, request):
if not request.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
if hasattr(request, 'user') and request.user.is_authenticated():
user = request.user
@robinkraft
robinkraft / s3bucketsize.py
Last active October 11, 2024 16:44
Simple python script to calculate size of S3 buckets
import sys
import boto
# based on http://www.quora.com/Amazon-S3/What-is-the-fastest-way-to-measure-the-total-size-of-an-S3-bucket
# assumes you've already configured your access id & secret key
s3 = boto.connect_s3()
@jacobian
jacobian / models.py
Created February 15, 2011 18:11
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):