コード例 #1
0
	def save(self, contato=None):
   		nome = self.cleaned_data.get('first_name')
   		sobrenome = self.cleaned_data.get('last_name')
   		email = self.cleaned_data.get('email')
   		twitter = self.cleaned_data.get('twitter')
   		# Se contato existe carrega os campos
   		if contato:
   			contato.first_name = nome
   			contato.last_name = sobrenome
   			contato.email = email
   			contato.twitter = twitter
   			contato.save()
   			return contato
   		# Se contato não existe então cria novo
   		else:
   			novo_contato = Contact(
	   			first_name=nome,
   				last_name=sobrenome,
   				email=email,
   				twitter=twitter
			)
   			novo_contato.save()
   			return novo_contato