Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
'''
Tricky admin -> xadmin merger.
Alex Moiseenko aka IMDagger.
'''
import logging
import types
from functools import wraps, update_wrapper
from django.http import HttpRequest
from django.contrib.admin import ModelAdmin
#############################################
# Push de la rama actual
git push origin $rama_actual
#############################################
# Volver a un commit anterior, descartando los cambios
git reset --HARD $SHA1
#############################################
# Ver y descargar Ramas remotas
@gengue
gengue / models.py
Created July 11, 2015 19:49
Time Spamped Model
class TimeStampedModel(models.Model):
"""
Una clase abstracta que registra la fecha de creacion y
modificacion del modelo
"""
created = models.DateTimeField(auto_now_add=True, verbose_name="fecha de creacion")
modified = models.DateTimeField(auto_now=True, verbose_name="fecha de modificacion")
class Meta:
abstract = True
@gengue
gengue / admin.py
Created July 19, 2015 15:26
Create a custom user in Django1.8
"""
file: profiles/admin.py
"""
from django.contrib import admin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm, ReadOnlyPasswordHashField
from .models import User
# Formulario de creacion de usuario
class UserCreationForm(UserCreationForm):
@gengue
gengue / admin.py
Last active August 29, 2015 14:25
Image and price display with placehold.it in django admin
class ClothAdmin(admin.ModelAdmin):
list_display = ('name', 'category', 'description', 'price_display', 'image_display',)
search_fields = ('name', 'category', 'description', 'price',)
list_filter = ('category',)
def price_display(self, obj):
return '${:20,d}'.format(obj.price)
price_display.short_description = 'precio'
price_display.admin_order_field = 'price'
class InstanceMixin(object):
def add_arguments(self):
return {'empresa':self.request.empresa}
def get_form_kwargs(self):
"""
Returns the keyword arguments for instanciating the form.
"""
kwargs = super(InstanceMixin, self).get_form_kwargs()
@gengue
gengue / gist:985d53ef848bad362a78
Last active August 29, 2015 14:25 — forked from thiamteck/gist:877276
JQuery Datepicker with Month and Year only
$(document).ready(function(){
$(".monthPicker").datepicker({
dateFormat: 'mm-yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
@gengue
gengue / jquery.location_picker.js
Last active April 4, 2022 09:45
Django admin Google maps Location picker (api v3)
google.load("maps", "3");
$(document).unload(function(){
GUnload();
});
$(document).ready(function(){
$("input.location_picker").each(function (i) {
var map = document.createElement('div');
map.className = "location_picker_map";
@gengue
gengue / style.css
Created August 19, 2015 00:15
center and crop image with css
img {
object-fit: cover;
}
@gengue
gengue / angular_events.js
Created August 20, 2015 03:15
Angular events tutorial
//Source http://stackoverflow.com/questions/14502006/working-with-scope-emit-and-on
/*
First of all, parent-child scope relation does matter. You have two possibilities to emit some event:
$broadcast -- dispatches the event downwards to all child scopes,
$emit -- dispatches the event upwards through the scope hierarchy.
I don't know anything about your controllers (scopes) relation, but there are several options:
If scope of firstCtrl is parent of the secondCtrl scope, your code should work by replacing $emit by $broadcast in firstCtrl:
*/