This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if user.groups.filter(name=group_name).count(): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[global] | |
timeout = 6000 | |
index-url = https://pypi.douban.com/simple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.python.org/library/sys.html | |
import sys | |
print(sys.executable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import connection, transaction | |
cursor = connection.cursor() # 获得一个游标(cursor)对象 | |
cursor.execute('update order_invoiceinfo set type = 1') | |
transaction.commit() # 提交到数据库 | |
# # 更新操作 | |
# cursor.execute('update other_other2 set name ="李四" where id=%s', [3]) # 执行sql语句 | |
# transaction.commit_unless_managed() # 提交到数据库 | |
# # 查询操作 | |
# cursor.execute('select * from other_other2 where id>%s', [1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RAVEN_CONFIG = { | |
'dsn': '<your-dsn-here>', | |
} | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': True, | |
'root': { | |
'level': 'WARNING', | |
'handlers': ['sentry'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Changing field 'MyTable.associated' | |
# db.alter_column(u'data_mytable', 'associated', | |
# self.gf('django.db.models.fields.IntegerField')() | |
# ) | |
db.execute( | |
'ALTER TABLE "data_mytable" ' | |
'ALTER COLUMN "associated" DROP DEFAULT, ' | |
'ALTER COLUMN "associated" DROP NOT NULL, ' | |
'ALTER COLUMN "associated" TYPE INTEGER ' | |
'USING ' |
OlderNewer