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 serialize(self): | |
obj = {} | |
for field in self._meta.fields: | |
value = field.value_from_object(self) | |
if isinstance(value, datetime.datetime): | |
obj[field.name] = field.value_to_string(self) | |
else: | |
obj[field.name] = value | |
return obj |
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
# standard lib | |
import hashlib | |
# django | |
from django.core.cache import cache | |
from django.utils.encoding import force_bytes | |
from django.utils.http import urlquote | |
def make_template_fragment_key(fragment_name, vary_on=[]): |
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
@classmethod | |
def my_func(cls, *args): | |
''' | |
A model function -- not a full Django View. | |
''' | |
with transaction.commit_manually(using='custom_connection'): | |
obj = OtherModel.objects.get(...) | |
try: | |
# do stuff | |
obj.save() |
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
CREATE TABLE `persons` ( | |
`sid` int(11) NOT NULL, | |
`is_active_user` tinyint(1) NOT NULL, | |
`is_premium` tinyint(1) NOT NULL, | |
`is_staff` tinyint(1) NOT NULL, | |
`is_superuser` tinyint(1) NOT NULL, | |
`is_deactivated` tinyint(1) NOT NULL, | |
`is_merged_out` tinyint(1) NOT NULL, | |
`password` varchar(128) NOT NULL, | |
`last_login` datetime DEFAULT NULL, |
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 lxml import etree | |
from StringIO import StringIO | |
from django.utils.encoding import smart_str | |
# Skip down to the bottom of this massive XML blob for more fun! | |
content = """<?xml version="1.0" encoding="utf-8"?> | |
<Root xsi:noNamespaceSchemaLocation="Questionnaire88_Template.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<ResponseHeader Code="101" Date="2015-11-06T22:09:53.4155282Z"> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<Root> | |
<Vessel> | |
<Updated>2015-01-01</Updated> | |
</Vessel> | |
</Root> |
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
[ | |
{ | |
"id": 1, | |
"name": "Yay" | |
} | |
] |
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 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', |
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
// Copyright 2013 The Flutter Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} |
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
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | |
// for details. All rights reserved. Use of this source code is governed by a | |
// BSD-style license that can be found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override |
OlderNewer