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
| def update_with_last_modified_time(qs, **kwargs): | |
| # This function adds any auto_now field to the update call because QuerySet.update() doesn't do it :X | |
| model_fields = qs.model._meta.get_fields() | |
| fields_and_value_map = {} | |
| for field in model_fields: | |
| try: | |
| auto_now = field.__getattribute__('auto_now') | |
| except AttributeError: | |
| auto_now = False |
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.contrib.admin import ModelAdmin | |
| class MyTableAdmin(ModelAdmin): | |
| ... | |
| paginator = LargeTablePaginator | |
| ... | |
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
| WITH user_ids AS | |
| (SELECT id | |
| FROM user | |
| WHERE account_id IN | |
| (SELECT generate_series(1,1000))) | |
| SELECT purchase.id | |
| FROM purchase | |
| WHERE user_id IN | |
| (SELECT id | |
| FROM user_ids); |
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 tablename, | |
| indexname, | |
| indexdef | |
| FROM pg_indexes | |
| WHERE tablename = '$$table_name$$' |
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 spray.json._ | |
| import DefaultJsonProtocol._ | |
| object Main extends App { | |
| class Card(val cardId: String, val name: String, val cardType: String, val effortHours: Double) { | |
| def formatCard(idx: Int): String = { | |
| idx + ". " + name + ": [" + effortHours + " hour(s)]" | |
| } |
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
| class Subject(object): | |
| def __init__(self): | |
| self.observer_list = [] | |
| def register_observer(obs): | |
| self.observer_list.append(obs) | |
| def remove_observer(obs): | |
| if obs in self.observer_list: | |
| self.observer_list.remove(obs) |
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
| class NewsGetterMachine(object): | |
| def __init__(self): | |
| self.news = None | |
| def get_news(): | |
| return self.news | |
| def news_flash(): | |
| news = self.get_news() |
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
| # Flying Behavior | |
| class FlyBehavior(object): | |
| def fly(): | |
| raise NotImplementedError | |
| class FlyWithWings(FlyBehavior): | |
| def fly(): | |
| print "I am flying!" | |
| class FlyNoWay(FlyBehavior): |
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
| class Duck(object): | |
| def quack(): | |
| print "Quack! Quack!" | |
| def swim(): | |
| print "Yaay I am swimming!" | |
| def display(): | |
| raise NotImplementedError |
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
| class MyModelIndex(AutoPrepareTextIndexMixin, CelerySearchIndex, indexes.Indexable): | |
| model_pk = indexes.IntegerField(model_attr='pk') # This is required | |
| text = indexes.EdgeNgramField(document=True) # This too | |
| some_boolean = indexes.IntegerField(model_attr='some_boolean') | |
| # Filters should map to the exact field name that the admin will access them by. | |
| # Example: foreign keys are accessed by FKModel__id. This is for filters | |
| rel_model = indexes.IntegerField(model_attr='rel_model__id') | |
| document_fields = ['name', 'nickname', 'rel_model__title'] # ^_^ |
NewerOlder