Re: Perform a join in 5 tables or more than that USIN ORM

2022-01-30 Thread narendra thapa
here are my models serializers and views and i need a data in tree
structure. the function in view file is get_course_tree_view
and rest are the models and serializers I need to join all these tables
together to fetch data i was able to do only three joins

On Sun, Jan 30, 2022 at 8:37 PM Sam Chaffy  wrote:

> Yes you can
>
> What’s your model look like ?
>
> On Sun, Jan 30, 2022 at 7:26 AM narendra...@gmail.com <
> narendrathapa...@gmail.com> wrote:
>
>> hello folks,
>>  any django ex[ert here, I want to know if anybody can do multiple join
>> more than 5 tables at once using ORM
>> Prefetch,prefetch_related,select_related using any of these or in a
>> different way please ping, or just write over here how can we solve that. i
>> didn't get any clue
>> help will be appreciated
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/a2097a78-1446-4456-83a1-c96059a12a1dn%40googlegroups.com
>> 
>> .
>>
> --
> Oussama Chafiqui
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPvcp%2BVtMGtBmC5RZNn8k_-6WRhY9UCbMg%3DqjFZDH7dc81%2B%3DCw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEtntjVFE24MnzyE27jccambxLm63%3D4C1FH4%3D5Ls3h8mspOcyw%40mail.gmail.com.
from django.db import models
from django.conf import settings
from django.db.models.signals import pre_save
from django.utils.text import slugify
from django.dispatch import receiver
# Create your models here.


class course_categories(models.Model):
deleted_flag = [('y', 'yes'), ('n', 'no')]
category_name = models.CharField(max_length=50, unique=True)
category_slug = models.SlugField(max_length=100, unique=True)
course_categories_code = models.CharField(max_length=7, unique=True)
created_by = models.CharField(max_length=50, null=True, blank=True)
created_date = models.DateTimeField(auto_now_add=True)
modified_by = models.CharField(max_length=50, blank=True, null=True)
modified_date = models.DateTimeField(
auto_now_add=False, blank=True, null=True)
is_deleted_flag = models.CharField(
max_length=1, choices=deleted_flag, default='n')

def __str__(self):
return self.category_name


def create_course_category_slug(instance, new_slug=None):

slug = slugify(instance.category_name)
if new_slug is not None:
slug = new_slug
slug = "%s-%s" % (slug, instance.course_categories_code)
qs = course_categories.objects.filter(category_slug=slug).order_by("-id")
exists = qs.exists()
if exists:
new_slug = "%s-%s" % (slug, qs.first().id)
return create_course_category_slug(instance, new_slug=new_slug)
print("slug", slug)
return slug


@receiver(pre_save, sender=course_categories)
def pre_save_course_categories_receiver(sender, instance, *args, **kwargs):
# if not instance.category_slug:
instance.category_slug = create_course_category_slug(instance)


class courses(models.Model):
deleted_flag = [('y', 'yes'), ('n', 'no')]
course_name = models.CharField(max_length=70)
course_categories = models.ForeignKey(
'course_categories', related_name='courses', on_delete=models.CASCADE)
course_slug = models.SlugField(unique=True)
course_code = models.CharField(max_length=7, unique=True)
created_by = models.CharField(max_length=50, null=True, blank=True)
created_date = models.DateTimeField(auto_now_add=True)
modified_by = models.CharField(max_length=50, blank=True, null=True)
modified_date = models.DateTimeField(
auto_now_add=False, blank=True, null=True)
is_deleted_flag = models.CharField(
max_length=1, choices=deleted_flag, default='n')

def __str__(self):
return self.course_name


def create_course_slug(instance, new_slug=None):

slug = slugify(instance.course_name)
if new_slug is not None:
slug = new_slug
slug = "%s-%s" % (slug, instance

Reusable form templates not working in Django 4.0?!

2022-01-30 Thread Sammeeey
Please find the respective post in the Django Forum 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d1082262-7028-484b-968b-487ea128e59cn%40googlegroups.com.


Re: Perform a join in 5 tables or more than that USIN ORM

2022-01-30 Thread Sam Chaffy
Yes you can

What’s your model look like ?

On Sun, Jan 30, 2022 at 7:26 AM narendra...@gmail.com <
narendrathapa...@gmail.com> wrote:

> hello folks,
>  any django ex[ert here, I want to know if anybody can do multiple join
> more than 5 tables at once using ORM
> Prefetch,prefetch_related,select_related using any of these or in a
> different way please ping, or just write over here how can we solve that. i
> didn't get any clue
> help will be appreciated
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a2097a78-1446-4456-83a1-c96059a12a1dn%40googlegroups.com
> 
> .
>
-- 
Oussama Chafiqui

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPvcp%2BVtMGtBmC5RZNn8k_-6WRhY9UCbMg%3DqjFZDH7dc81%2B%3DCw%40mail.gmail.com.


Perform a join in 5 tables or more than that USIN ORM

2022-01-30 Thread narendra...@gmail.com
hello folks,
 any django ex[ert here, I want to know if anybody can do multiple join 
more than 5 tables at once using ORM 
Prefetch,prefetch_related,select_related using any of these or in a 
different way please ping, or just write over here how can we solve that. i 
didn't get any clue
help will be appreciated

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a2097a78-1446-4456-83a1-c96059a12a1dn%40googlegroups.com.


Re: Syntax to Generate salary for next month

2022-01-30 Thread AliHassanRaza Khan
Or get method if you want to retrieve a single value

On Sun, 30 Jan 2022, 1:45 pm AliHassanRaza Khan, 
wrote:

> use filter method
>
> On Sun, 30 Jan 2022, 4:50 am Feroz Ahmed,  wrote:
>
>> Hi,
>>
>> I came across the problem, how to generate salary for upcoming month (
>> records are of month January in db)
>>
>>
>>
>>
>>
>> *I have records in django db.*
>>
>> *Insert of new record*
>>
>> *update / delete / hideof record functions are ok *
>>
>>
>>
>> *Request your support, to generate the salary for month February (by
>> clicking on generate salary button) see pic2 below.*
>>
>>
>>
>> *syntax to code in views??*
>>
>>
>>
>> model.py
>>
>> Fields are :month , cmonth, name, salary
>>
>>
>>
>> * month field is in list format , (values from January to December)
>>
>>
>> *pic1*
>>
>>
>>
>>
>>
>>
>>
>> *pic2*
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/61f5d2a5.1c69fb81.f300.5a1c%40mx.google.com
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD54KQaYkvbm-oki3ijjom13ZSviqyMFs%2ByfznuP3%3DvdNQPMFA%40mail.gmail.com.


Re: Syntax to Generate salary for next month

2022-01-30 Thread AliHassanRaza Khan
use filter method

On Sun, 30 Jan 2022, 4:50 am Feroz Ahmed,  wrote:

> Hi,
>
> I came across the problem, how to generate salary for upcoming month (
> records are of month January in db)
>
>
>
>
>
> *I have records in django db.*
>
> *Insert of new record*
>
> *update / delete / hideof record functions are ok *
>
>
>
> *Request your support, to generate the salary for month February (by
> clicking on generate salary button) see pic2 below.*
>
>
>
> *syntax to code in views??*
>
>
>
> model.py
>
> Fields are :month , cmonth, name, salary
>
>
>
> * month field is in list format , (values from January to December)
>
>
> *pic1*
>
>
>
>
>
>
>
> *pic2*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/61f5d2a5.1c69fb81.f300.5a1c%40mx.google.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD54KQYLH8ROS13ksObkLRd7V8Z3yfK0%3DZ4G0jbuSfe%3D46qoSw%40mail.gmail.com.