Skip to content

Instantly share code, notes, and snippets.

View samirbr's full-sized avatar

Samir El Aouar samirbr

View GitHub Profile
parent = get_object_or_404(queryset, id=int(parent_id), user=rootuser)
data = Question.objects.filter(parent=parent, deleted=False)
serializer = QuestionListSerializer(data)
serializer.data
erro:
IndexError Traceback (most recent call last)
@samirbr
samirbr / dados.py
Last active February 1, 2016 20:35
if isinstance(dados, dict):
Passagens126.objects.create(**to_kwargs(dados))
else:
for item in dados:
print(item)
Passagens126.objects.create(**to_kwargs(item))
var $input = $('#id_cpf');
$input[0].sent = false;
$input.keyup(function () {
var value = $(this).val();
if (value.length === 11 && !this.sent){
this.sent = true;
$.ajax({ /* ajax goes here */ });
value = { 'a':
{
'c': 1,
'd': [
{ 'a': 1 }
]
}
}
from django.db import models
import json
class JSONField(models.TextField):
def __init__(self, verbose_name=None, name=None, default=None, **kwargs):
models.TextField.__init__(self, verbose_name, name, **kwargs)
def to_python(self, value):
if isinstance(value, six.string_types) or value is None:
return value
# coding=utf-8
from django.conf.urls import patterns, url, include
from rest_framework import routers
from .views import (ClientPlanViewSet, PlanViewSet,
ClientPlanReportViewSet, ReportUsage)
router = routers.DefaultRouter()
router.register(r'billing/manage', ClientPlanViewSet,
base_name='billing_manage')
moment.locale('pt-BR');
$scope.months = [];
$scope.series = [];
$scope.data = [];
$http.get('/nodes')
.then(function(response) {
var months = {};
$scope.questionnaires = [];
$scope.selectAll = function() {
$scope.selected = $scope.questionnaires.map(function(q) {
return q.id;
});
};
$scope.clear = function() {
$scope.selected = [];
@samirbr
samirbr / Client.js
Last active December 28, 2015 19:58
app.factory('Client', function() {
function Client(obj) {
obj.created = new Date(obj.created);
angular.extend(this, obj);
}
return Client;
});
def do_update(self, obj, request):
obj.user = request.user.get_root()
serializer = DeviceSerializer(obj, data=request.data, partial=True)
is_create = obj.pk is None
if serializer.is_valid():
serializer.save()
if is_create: