This file contains hidden or 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
| import os | |
| import configparser | |
| class Config: | |
| """ Get config from config file or environment variables. | |
| The priority order of config is: Config file > Environment > default_value. | |
| The env var is composed by: [SECTION]_[OPTION] | |
| For example: | |
| get_or_else('smtp', 'BIND_ADDRESS', '127.0.0.1') |
This file contains hidden or 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
| __version__ = "0.1.6.8" | |
| if __name__ == "__main__": | |
| import sys | |
| import argparse | |
| def increment_line(args): | |
| vi = [int(i) for i in __version__.split('.')] | |
| print('current version: %s' % __version__) |
This file contains hidden or 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
| SELECT CONCAT("ALTER TABLE `", TABLE_NAME,"` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;") AS ExecuteTheString | |
| FROM INFORMATION_SCHEMA.TABLES | |
| WHERE TABLE_SCHEMA="[YOUR DATABASE NAME]" | |
| AND TABLE_TYPE="BASE TABLE"; | |
| SELECT @@character_set_database, @@collation_database; |
This file contains hidden or 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 models | |
| from django.contrib.contenttypes.models import ContentType | |
| from django.contrib.contenttypes import generic | |
| class Poll(models.Model): | |
| question = models.CharField(max_length=500) | |
| answers = # ... | |
| # ... | |
| limit = models.Q(app_label='your_app', model='page') | \ |
This file contains hidden or 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
| -- You can use pg_terminate_backend() to kill a connection. You have to be superuser to use this function. This works on all operating systems the same. | |
| SELECT | |
| pg_terminate_backend(pid) | |
| FROM | |
| pg_stat_activity | |
| WHERE | |
| -- don't kill my own connection! | |
| pid <> pg_backend_pid() | |
| -- don't kill the connections to other databases |
This file contains hidden or 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
| # views.py | |
| from rest_framework import exceptions | |
| from rest_framework import generics | |
| from myapp import models | |
| from myapp import serializers as ser | |
| class MethodSerializerView(object): | |
| ''' |
This file contains hidden or 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
| # serializers.py | |
| from rest_framework import serializers | |
| from myapp import models | |
| class OrganizationListViewSerializer(serializers.ModelSerializer): | |
| class Meta: | |
| model = models.Organization | |
| fields = '__all__' |
This file contains hidden or 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
| # models.py | |
| import uuid | |
| from django.db import models | |
| class Organization(models.Model): | |
| org_uuid = models.UUIDField( | |
| primary_key=True, default=uuid.uuid4, editable=False) | |
| name = models.CharField(max_length=40) |
NewerOlder