Skip to content

Instantly share code, notes, and snippets.

View rg3915's full-sized avatar
🏠
Working from home

Regis Santos rg3915

🏠
Working from home
View GitHub Profile
@neara
neara / forms.py
Last active June 10, 2024 15:30
Django Class Based Views and Inline Formset Example
from django.forms import ModelForm
from django.forms.models import inlineformset_factory
from models import Sponsor, Sponsorship
class SponsorForm(ModelForm):
class Meta:
model = Sponsor
@goldhand
goldhand / Django + Ajax dynamic forms .py
Last active September 29, 2023 06:32
Django form with Ajax. A simple Task model that can be updated using a CBV with an AJAX mixin. The view sends post data with ajax then updates the view with a callback to a DetailView with a json mixin.There is an abstract CBV, AjaxableResponseMixin, based on the example form django docs, that is subclassed in the TaskUpdateView CBV. TaskUpdateV…
#models.py
class Task(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
def __unicode__(self):
return self.title
@fmasanori
fmasanori / ChuckJokesPython3.py
Last active September 5, 2023 11:36
Chuck Norris Nerd Jokes
from urllib.request import Request, urlopen
import json
req = Request(
url='https://api.chucknorris.io/jokes/random',
headers={'User-Agent': 'Mozilla/5.0'}
)
resp = urlopen(req).read()
data = json.loads(resp.decode('utf-8'))
@fmasanori
fmasanori / Facebook Profile Image Python 3x.py
Created January 29, 2013 20:06
Python 3.x Facebook Profile Image
import urllib.request
import json
user = 'fmasanori'
url = 'https://graph.facebook.com/'+user+'/picture?type=large'
figura = urllib.request.urlopen(url).read()
arquivo = user + '.jpg'
f = open (arquivo, 'wb')
f.write(figura)
@fmasanori
fmasanori / Facebook Profile Python 3x.py
Created January 29, 2013 19:58
Python 3.x Facebook Profile
import urllib.request
import json
from pprint import pprint
url = 'https://graph.facebook.com/fmasanori'
resp = urllib.request.urlopen(url).read()
data = json.loads(resp.decode('utf-8'))
pprint (data)