Skip to content

Instantly share code, notes, and snippets.

View luxcem's full-sized avatar
🚀

A luxcem

🚀
View GitHub Profile
@luxcem
luxcem / create_child_instance_from_parent.py
Last active August 29, 2015 14:23
Django Create child instance from parent instance
def create_child_instance_from_parent(child_cls, parent_instance):
parent_cls = parent_instance.__class__
field = child_cls._meta.get_ancestor_link(parent_cls).column
# We could specify a parent_identifier which is a unique field in
# the parent class that link child to parent
if hasattr(child_cls, 'parent_identifier'):
try:
child_instance = child_cls.objects.get(
**{child_cls.child_parent_identifier:
@luxcem
luxcem / gist:eda431ad0c3cd8cbada0
Created February 23, 2015 17:34
Django model inheritance: create a subclass using existing super class
# https://stackoverflow.com/questions/9821935/django-model-inheritance-create-a-subclass-using-existing-super-class
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
class Restaurant(Place):
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
function parseHashBangArgs(aURL) {
aURL = aURL || window.location.href;
var vars = {};
var hashes = aURL.slice(aURL.indexOf('#') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
var hash = hashes[i].split('=');