What do you want to save?
Add Code snippet
New code examples
-
Python 2021-10-24 04:31:13
django get part of queryset
# According to documentation # Limiting QuerySets # This is the equivalent of SQL’s LIMIT and OFFSET clauses. # For example, this returns the first 5 objects (LIMIT 5): >>> Entry.objects.all()[:5] # This returns the sixth through tenth o... Add solution -
Python 2021-10-22 14:45:05
display data from database in django
data = Students.objects.all() stu = { "student_number": data } return render_to_response("login/profile.html", stu) // in html file : {% for student in student_number %} {{ student.f_name}} {{ student.l_name }} {{ stud... Add solution -
Python 2021-10-21 07:41:06
register login serializer django
from rest_framework import serializers from rest_framework.validators import UniqueValidator from django.contrib.auth.models import User class UserSerializer(serializers.ModelSerializer): email = serializers.EmailField( required=True, ... Add solution -
Python 2021-10-19 21:12:09
build rest apis with django rest framework and python
# Package installment in terminal(Recommended : Activate virtual env) pip install djangorestframework #Project>Settings.py INSTALLED_APPS += ['rest_framework', 'rest_framework.authtoken'] REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ ... Add solution -
Python 2021-10-19 21:06:07
how to get SITE_ID in django....shell
[ ... banner ... ] >>> >>> from django.contrib.sites.models import Site >>> >>> sorted([(site.id,site.name) for site in Site.objects.all()]) [(1, u'www.lvh.me'), (2, u'example.com'), (3, u'www.example.com'),...] >>... Add solution -
Python 2021-10-17 00:24:05
how to count post by category django
#views.py from django.db.models import Count # You should change post in Count function based on your model. categories = Category.objects.all().annotate(posts_count=Count('post')) #Then you will have access to number of posts for each category: for cate... Add solution -
Other 2021-10-16 20:52:07
download files from s3 bucket filtered by date
from boto3.session import Session from datetime import date, timedelta import boto3 import re def Download_pdf_specifc_date_subfolder(bucket_name,download_path) ACCESS_KEY = 'XYZ' SECRET_KEY = 'ABC' Bucket_name=bucket_name # code to cre... Add solution -
Python 2021-10-11 11:41:04
Using Paginator in a view function
from django.contrib.auth.models import User from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger def index(request): user_list = User.objects.all() page = request.GET.get('page', 1) paginator = Paginator(user_list, 10) ... Add solution