Skip to content

Instantly share code, notes, and snippets.

# defining Custom Querysets methods for the manager
class StudentQuerySet(QuerySet):
def male(self):
return self.filter(gender='male')
def female(self):
return self.filter(gender='female')
def age_greater_or_equal_to(self, age):
return self.filter(age__gte=age)
>>> Student.objects.get_males().get_students_age_less_or_equal(23)
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'get_students_age_less_or_equal'
>>> from student.models import Student
# Get the total number of students.
>>> student = Student.objects.get_total_students()
>>> student # 6 (ans according to the data in database)
# Get students with age less than or equal to the given age.
>>> student = Student.objects.get_students_age_less_or_equal(22)
>>> student # returns students with age less than or equal to the given age
from django.db.models import Manager, Q, Sum
from datetime import datetime
class StudentManager(Manager):
def get_total_students(self):
return self.all().count()
def get_students_age_less_or_equal(self, age):
return self.filter(age__lte=age)
from django.db import models
from .managers import StudentManager, MaleManager, FemaleManager, StudentModifyManager, StudentQuerySet
from django.core.validators import MaxValueValidator
SEMESTER = (
('sem1', 'sem1'),
('sem2', 'sem2'),
('sem3', 'sem3'),
('sem4', 'sem4'),
)
from django.contrib.auth.models import User
user = User.objects.get(id=1)
; ================================
; celery beat supervisor
; ================================
; the name of your supervisord program
[program:voicechatproject_celery_beat]
; Set full path to celery program if using virtualenv
command=/home/er190622005/Botree/VoiceChat/chat_venv/bin/celery beat -A voicechatproject --loglevel=INFO
; ==================================
; celery worker supervisor
; ==================================
; the name of your supervisord program
[program:voicechatproject_celery_worker]
; Set full path to celery program if using virtualenv
command=/home/er190622005/Botree/VoiceChat/chat_venv/bin/celery worker -A voicechatproject --loglevel=INFO
from botocore.exceptions import ClientError
from celery import task
from message.models import *
from celery.schedules import crontab
from celery.task import periodic_task
from django.db.models import Q
import datetime,boto3
from django.conf import settings
from django.db import IntegrityError, transaction
BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Calcutta'