Skip to content

Instantly share code, notes, and snippets.

View bluethon's full-sized avatar
🤣
free

Haibo Jia bluethon

🤣
free
  • Beijing, China
View GitHub Profile
from django.http import QueryDict
def url_with_querystring(path, query_dict):
""" URL查询参数拼接 """
qdict = QueryDict('', mutable=True)
qdict.update(query_dict)
return path + '?' + qdict.urlencode()
url_dict = {
'course': course,
@bluethon
bluethon / 0_reuse_code.js
Created October 15, 2016 06:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@bluethon
bluethon / Find_full_path_of_python_interpreter
Created October 4, 2016 03:34
python中获取解释器路径
# http://docs.python.org/library/sys.html
import sys
print(sys.executable)
@bluethon
bluethon / pip.conf
Created September 30, 2016 09:45
修改pip源 ~/.pip/pip.conf
[global]
timeout = 6000
index-url = https://pypi.douban.com/simple
@bluethon
bluethon / check_user_group.py
Created September 11, 2016 07:33
check if user have the group
if user.groups.filter(name=group_name).count():
pass
@bluethon
bluethon / model_define_groups.py
Last active September 11, 2016 07:00
group attribute demo
class some():
groups = models.ManyToManyField(
Group,
verbose_name='组',
blank=True,
# help_text='The groups this user belongs to. A user will get all '
# 'permissions granted to each of their groups.',
related_name="user_set",
related_query_name="user",
)
@bluethon
bluethon / create_group_and_permission.py
Last active September 11, 2016 06:47
group user get_or_create contenttype
# http://stackoverflow.com/questions/22250352/in-django-how-do-you-programmatically-create-a-group-with-permissions
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from api.models import Project
new_group, created = Group.objects.get_or_create(name='new_group')
# Code to add permission to group ???
ct = ContentType.objects.get_for_model(Project)
# Now what - Say I want to add 'Can add project' permission to new_group?
permission = Permission.objects.create(codename='can_add_project', name='Can add project', content_type=ct)