Skip to content

Instantly share code, notes, and snippets.

View marcgibbons's full-sized avatar

Marc Gibbons marcgibbons

View GitHub Profile
@marcgibbons
marcgibbons / concat_json_expression.py
Last active September 12, 2023 19:05
Expression to concatenate Django Postgres JSONField
from django.db.models.expressions import CombinedExpression, F, Value
from django.contrib.postgres.fields import JSONField
expression = CombinedExpression(
F('my_json_field'),
'||',
Value({'fizz': 'buzz'}, JSONField())
)
@marcgibbons
marcgibbons / trailing-slash
Created November 1, 2014 04:58
Append slash to end of string, pre-pend querystring `?` symbol
r"^([^\.^\?]+[^\/])(\?[^\/.]+)?$"
#
# Depends on: puppetlabs/stdlib
#
define buildsource(
$dir = $title,
$user = 'root',
$path = '/usr/bin:/bin',
$timeout = '0',
$options = ''
) {
class CigarList(ListCreateAPIView):
"""
Lists and creates cigars from the database.
"""
model = Cigar
serializer_class = CigarSerializer
@marcgibbons
marcgibbons / gist:5594126
Created May 16, 2013 18:55
Serializer ex
class CigarSerializer(serializers.ModelSerializer):
class Meta:
model = models.Cigar
@marcgibbons
marcgibbons / gist:5594120
Created May 16, 2013 18:53
Model example
class Cigar(models.Model):
name = models.CharField(max_length=25)
colour = models.CharField(max_length=30)
gauge = models.IntegerField()
length = models.IntegerField()
price = models.DecimalField(decimal_places=2, max_digits=5)
notes = models.TextField()
manufacturer = models.ForeignKey('Manufacturer')
@marcgibbons
marcgibbons / full_path_to_file
Created March 27, 2013 18:53
Refer to a file by it's full system path
os.path.join(os.path.dirname(__file__), 'myfile.txt')
@marcgibbons
marcgibbons / nose_settings
Created March 27, 2013 18:51
Preferred settings for django nose
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
SOUTH_TESTS_MIGRATE = False
NOSE_ARGS = ['--nocapture', '--nologcapture']