Kim Majali wrote on 03/06/2022
path('search', views.search, name='search'),
Read moreKim Majali wrote on 03/06/2022
Kim Majali wrote on 02/06/2022
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import User
class Movies(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
genre = models.CharField(max_length=200)
def __unicode__(self):
return self.title
def get_absolute_url(self):
return reverse('CRUD_FBVs:movies_edit', kwargs={'pk': self.pk})
Read moreKim Majali wrote on 02/06/2022
from django.shortcuts import render
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from .models import Listing
def index(request):
listings = Listing.objects.order_by('-list_date').filter(is_published=True)
paginator = Paginator(listings, 6)
page = request.GET.get('page')
paged_listings = paginator.get_page(page)
context = {
'listings' : paged_listings
}
return render(request, 'listings/listings.html', context)
Read moreKim Majali wrote on 02/06/2022
record = User.objects.get(id=request.POST['id'])
record.delete()
# or
User.objects.get(id=request.POST['id']).delete()
# With try
try:
record = User.objects.get(id=request.POST['id'])
record.delete()
except Exception as e:
print("Exception Update balance ==========================")
print(e)
print("End of Exception ==========================")
Read more