Kim Majali wrote on 02/06/2022
from django.contrib.gis.db import models
class Contact(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField()
address = models.CharField(max_length=100)
phone = models.CharField(max_length=50)
Read moreKim Majali wrote on 02/06/2022
p1 = Person(first_name="Vuyisile", last_name="Ndlovu")
p1.save()
Read moreKim Majali wrote on 02/06/2022
try:
record = Account.objects.filter(id=1).first()
record.balance = new_amount
record.save()
messages.success(request, "Company info has been updated." )
except Exception as e:
messages.error(request, "Something went wrong.")
print("Exception Update balance ==========================")
print(e)
print("End of Exception ==========================")
Read moreKim Majali wrote on 02/06/2022
from django.conf import settings
class HomePageView(TemplateView):
template_name = 'home.html'
def get_context_data(self, **kwargs):
context =super().get_context_data(**kwargs)
context['key'] = settings.PUBLISHABLE_KEY
return context
path('charge/', views.charge, name='payment_success'),
def charge(request):
if request.method == 'POST':
charge = stripe.Charge.create(
amount=500,
currency='usd',
description='A Django charge',
source=request.POST['stripeToken']
)
return render(request, 'payment_success.html')
Topics: ModelsIntegrations