Re: How to make admin duplicate action for an object with all related foreign key and one-to-one fields?
thank you guys a lot. Literally saved me) Best wishes On Tuesday, January 11, 2022 at 10:51:10 PM UTC+6 croch...@gmail.com wrote: > Hi, you need read this first > https://docs.djangoproject.com/en/4.0/ref/contrib/admin/actions/ > and then this > > https://stackoverflow.com/questions/3989894/create-a-django-admin-action-to-duplicate-a-record > > Cheers > > > On Tue, Jan 11, 2022 at 3:44 AM skumar pandey > wrote: > >> Can you please create a user who can update their profile using django >> rest framework and along with jwt authentication its a request. >> >> On Tue, 11 Jan 2022, 12:24 pm Alibek Khojabekov, >> wrote: >> >>> Hello everyone, >>> I am bit confused about making duplicate of a Course object in admin >>> actions with all related child objects. So my Models are: >>> >>> class Course(models.Model): >>> PROGRAMMING = 1 >>> DESIGN = 2 >>> ROBOTICS = 3 >>> DIGITAL_LITERACY = 4 >>> IT_ENTREPRENEURSHIP = 5 >>> CATEGORY_CHOICES = ( >>> (PROGRAMMING, 'Программирование, IT предпринимательство'), >>> (DESIGN, 'Компьютерная графика и медиа'), >>> (ROBOTICS, 'Робототехника и электроника'), >>> (DIGITAL_LITERACY, 'Компьютерная грамотность'), >>> ) >>> >>> NEW = 1 >>> PROGRESS = 2 >>> READY = 3 >>> >>> STATUS_CHOICES = ( >>> (NEW, 'Новый'), >>> (PROGRESS, 'В прогрессе'), >>> (READY, 'Готово'), >>> ) >>> >>> class Meta: >>> ordering = ['pk'] >>> >>> course_type = models.ForeignKey( >>> Category, related_name='courses', on_delete=models.SET_NULL, blank=True, >>> null=True, db_index=True) >>> name = models.CharField(max_length=120, db_index=True) >>> short_description = models.TextField(blank=True, null=True) >>> description = models.TextField(blank=True, null=True) >>> image = models.FileField(upload_to=upload_path, null=True, blank=True) >>> icon = models.FileField(upload_to=upload_path, null=True, blank=True) >>> video_link = models.URLField(max_length=200, null=True, blank=True) >>> target_audience = models.TextField(blank=True, null=True) >>> price = models.DecimalField(max_digits=8, decimal_places=2, >>> default=0.00, validators=[ >>> MinValueValidator(Decimal('0.00'))], blank=True) >>> author = models.ForeignKey( >>> 'users.User', default=1, on_delete=models.SET_NULL, null=True) >>> language = models.CharField( >>> max_length=3, choices=settings.LANGUAGES, default='ru', db_index=True) >>> category = models.PositiveSmallIntegerField( >>> choices=CATEGORY_CHOICES, default=PROGRAMMING, db_index=True) >>> robotics_kit = models.ForeignKey( >>> RoboticsKit, related_name='courses', on_delete=models.SET_NULL, >>> blank=True, null=True) >>> course_class = models.ManyToManyField( >>> CourseClass, related_name='courses') >>> status = models.PositiveSmallIntegerField( >>> choices=STATUS_CHOICES, default=NEW, blank=True) >>> order_list = models.CharField(max_length=500, validators=[ >>> int_list_validator], blank=True, null=True) >>> created_date = models.DateTimeField(auto_now_add=True) >>> is_accessible = models.BooleanField(default=True, null=True, blank=True) >>> is_intro = models.BooleanField(default=False, null=True, blank=True) >>> projects = models.ManyToManyField( >>> "self", blank=True, related_name='courses') >>> # objects = DefaultSelectOrPrefetchManager( >>> # select_related=('robotics_kit', 'course_class', 'course_type')) >>> >>> def __str__(self): >>> return self.name >>> >>> class Section(models.Model): >>> class Meta: >>> ordering = ['pk'] >>> >>> course = models.ForeignKey( >>> Course, related_name='sections', on_delete=models.CASCADE) >>> name = models.CharField(max_length=120) >>> created_date = models.DateTimeField(auto_now_add=True) >>> order_list = models.CharField(max_length=500, validators=[ >>> int_list_validator], blank=True, null=True) >>> >>> def __str__(self): >>> return self.name >>> >>> class SubSection(models.Model): >>> class Meta: >>> ordering = ['pk'] >>> >>> section = models.ForeignKey( >>> Section, related_name='sub_sections', on_delete=models.CASCADE) >>> name = models.CharField(max_length=120) >>> goal = models.TextField(max_length=500, default='', blank=True, >>> null=True) >>> image = models.FileField(upload_to=upload_path, null=True, blank=True, >>> validators=[ >>> FileExtensionValidator(allowed_extensions=['jpg', 'png', 'jpeg'])]) >>> link = models.URLField(max_length=200, null=True, blank=True) >>> created_date = models.DateTimeField(auto_now_add=True) >>> order_list = models.CharField(max_length=500, validators=[ >>> int_list_validator], blank=True, null=True) >>> is_homework = models.BooleanField(default=False) >>> >>> materials = GenericRelation( >>> "Material", null=True, related_query_name='sub_section') >>> >>> comments = GenericRelation( >>> "Comment", null=True, related_query_name='sub_sections') >>> point = models.PositiveSmallIntegerField(default=0) >>> skills = models.ManyToManyField(Skill) >>> hours = models.PositiveIntegerField(default=0, blank=True) >>> >>> def __str__(self): >>> return self.name >>> >>> def get_absolute_url(self): >>> return
Re: How to make admin duplicate action for an object with all related foreign key and one-to-one fields?
Hi, you need read this first https://docs.djangoproject.com/en/4.0/ref/contrib/admin/actions/ and then this https://stackoverflow.com/questions/3989894/create-a-django-admin-action-to-duplicate-a-record Cheers On Tue, Jan 11, 2022 at 3:44 AM skumar pandey wrote: > Can you please create a user who can update their profile using django > rest framework and along with jwt authentication its a request. > > On Tue, 11 Jan 2022, 12:24 pm Alibek Khojabekov, < > alibek.khojabe...@nu.edu.kz> wrote: > >> Hello everyone, >> I am bit confused about making duplicate of a Course object in admin >> actions with all related child objects. So my Models are: >> >> class Course(models.Model): >> PROGRAMMING = 1 >> DESIGN = 2 >> ROBOTICS = 3 >> DIGITAL_LITERACY = 4 >> IT_ENTREPRENEURSHIP = 5 >> CATEGORY_CHOICES = ( >> (PROGRAMMING, 'Программирование, IT предпринимательство'), >> (DESIGN, 'Компьютерная графика и медиа'), >> (ROBOTICS, 'Робототехника и электроника'), >> (DIGITAL_LITERACY, 'Компьютерная грамотность'), >> ) >> >> NEW = 1 >> PROGRESS = 2 >> READY = 3 >> >> STATUS_CHOICES = ( >> (NEW, 'Новый'), >> (PROGRESS, 'В прогрессе'), >> (READY, 'Готово'), >> ) >> >> class Meta: >> ordering = ['pk'] >> >> course_type = models.ForeignKey( >> Category, related_name='courses', on_delete=models.SET_NULL, blank=True, >> null=True, db_index=True) >> name = models.CharField(max_length=120, db_index=True) >> short_description = models.TextField(blank=True, null=True) >> description = models.TextField(blank=True, null=True) >> image = models.FileField(upload_to=upload_path, null=True, blank=True) >> icon = models.FileField(upload_to=upload_path, null=True, blank=True) >> video_link = models.URLField(max_length=200, null=True, blank=True) >> target_audience = models.TextField(blank=True, null=True) >> price = models.DecimalField(max_digits=8, decimal_places=2, default=0.00, >> validators=[ >> MinValueValidator(Decimal('0.00'))], blank=True) >> author = models.ForeignKey( >> 'users.User', default=1, on_delete=models.SET_NULL, null=True) >> language = models.CharField( >> max_length=3, choices=settings.LANGUAGES, default='ru', db_index=True) >> category = models.PositiveSmallIntegerField( >> choices=CATEGORY_CHOICES, default=PROGRAMMING, db_index=True) >> robotics_kit = models.ForeignKey( >> RoboticsKit, related_name='courses', on_delete=models.SET_NULL, >> blank=True, null=True) >> course_class = models.ManyToManyField( >> CourseClass, related_name='courses') >> status = models.PositiveSmallIntegerField( >> choices=STATUS_CHOICES, default=NEW, blank=True) >> order_list = models.CharField(max_length=500, validators=[ >> int_list_validator], blank=True, null=True) >> created_date = models.DateTimeField(auto_now_add=True) >> is_accessible = models.BooleanField(default=True, null=True, blank=True) >> is_intro = models.BooleanField(default=False, null=True, blank=True) >> projects = models.ManyToManyField( >> "self", blank=True, related_name='courses') >> # objects = DefaultSelectOrPrefetchManager( >> # select_related=('robotics_kit', 'course_class', 'course_type')) >> >> def __str__(self): >> return self.name >> >> class Section(models.Model): >> class Meta: >> ordering = ['pk'] >> >> course = models.ForeignKey( >> Course, related_name='sections', on_delete=models.CASCADE) >> name = models.CharField(max_length=120) >> created_date = models.DateTimeField(auto_now_add=True) >> order_list = models.CharField(max_length=500, validators=[ >> int_list_validator], blank=True, null=True) >> >> def __str__(self): >> return self.name >> >> class SubSection(models.Model): >> class Meta: >> ordering = ['pk'] >> >> section = models.ForeignKey( >> Section, related_name='sub_sections', on_delete=models.CASCADE) >> name = models.CharField(max_length=120) >> goal = models.TextField(max_length=500, default='', blank=True, null=True) >> image = models.FileField(upload_to=upload_path, null=True, blank=True, >> validators=[ >> FileExtensionValidator(allowed_extensions=['jpg', 'png', 'jpeg'])]) >> link = models.URLField(max_length=200, null=True, blank=True) >> created_date = models.DateTimeField(auto_now_add=True) >> order_list = models.CharField(max_length=500, validators=[ >> int_list_validator], blank=True, null=True) >> is_homework = models.BooleanField(default=False) >> >> materials = GenericRelation( >> "Material", null=True, related_query_name='sub_section') >> >> comments = GenericRelation( >> "Comment", null=True, related_query_name='sub_sections') >> point = models.PositiveSmallIntegerField(default=0) >> skills = models.ManyToManyField(Skill) >> hours = models.PositiveIntegerField(default=0, blank=True) >> >> def __str__(self): >> return self.name >> >> def get_absolute_url(self): >> return reverse("sub_section", kwargs={"course_pk": self.section.course.pk >> , >> "section_pk": self.section.pk, "sub_section_pk": self.pk}) >> >> class Step(models.Model): >> class Meta: >> ordering = ['pk'] >> >> TEXT = 1 >> HINT = 2 >> TEST = 3 >> EXERCISE = 4 >>
Re: How to make admin duplicate action for an object with all related foreign key and one-to-one fields?
Can you please create a user who can update their profile using django rest framework and along with jwt authentication its a request. On Tue, 11 Jan 2022, 12:24 pm Alibek Khojabekov, < alibek.khojabe...@nu.edu.kz> wrote: > Hello everyone, > I am bit confused about making duplicate of a Course object in admin > actions with all related child objects. So my Models are: > > class Course(models.Model): > PROGRAMMING = 1 > DESIGN = 2 > ROBOTICS = 3 > DIGITAL_LITERACY = 4 > IT_ENTREPRENEURSHIP = 5 > CATEGORY_CHOICES = ( > (PROGRAMMING, 'Программирование, IT предпринимательство'), > (DESIGN, 'Компьютерная графика и медиа'), > (ROBOTICS, 'Робототехника и электроника'), > (DIGITAL_LITERACY, 'Компьютерная грамотность'), > ) > > NEW = 1 > PROGRESS = 2 > READY = 3 > > STATUS_CHOICES = ( > (NEW, 'Новый'), > (PROGRESS, 'В прогрессе'), > (READY, 'Готово'), > ) > > class Meta: > ordering = ['pk'] > > course_type = models.ForeignKey( > Category, related_name='courses', on_delete=models.SET_NULL, blank=True, > null=True, db_index=True) > name = models.CharField(max_length=120, db_index=True) > short_description = models.TextField(blank=True, null=True) > description = models.TextField(blank=True, null=True) > image = models.FileField(upload_to=upload_path, null=True, blank=True) > icon = models.FileField(upload_to=upload_path, null=True, blank=True) > video_link = models.URLField(max_length=200, null=True, blank=True) > target_audience = models.TextField(blank=True, null=True) > price = models.DecimalField(max_digits=8, decimal_places=2, default=0.00, > validators=[ > MinValueValidator(Decimal('0.00'))], blank=True) > author = models.ForeignKey( > 'users.User', default=1, on_delete=models.SET_NULL, null=True) > language = models.CharField( > max_length=3, choices=settings.LANGUAGES, default='ru', db_index=True) > category = models.PositiveSmallIntegerField( > choices=CATEGORY_CHOICES, default=PROGRAMMING, db_index=True) > robotics_kit = models.ForeignKey( > RoboticsKit, related_name='courses', on_delete=models.SET_NULL, > blank=True, null=True) > course_class = models.ManyToManyField( > CourseClass, related_name='courses') > status = models.PositiveSmallIntegerField( > choices=STATUS_CHOICES, default=NEW, blank=True) > order_list = models.CharField(max_length=500, validators=[ > int_list_validator], blank=True, null=True) > created_date = models.DateTimeField(auto_now_add=True) > is_accessible = models.BooleanField(default=True, null=True, blank=True) > is_intro = models.BooleanField(default=False, null=True, blank=True) > projects = models.ManyToManyField( > "self", blank=True, related_name='courses') > # objects = DefaultSelectOrPrefetchManager( > # select_related=('robotics_kit', 'course_class', 'course_type')) > > def __str__(self): > return self.name > > class Section(models.Model): > class Meta: > ordering = ['pk'] > > course = models.ForeignKey( > Course, related_name='sections', on_delete=models.CASCADE) > name = models.CharField(max_length=120) > created_date = models.DateTimeField(auto_now_add=True) > order_list = models.CharField(max_length=500, validators=[ > int_list_validator], blank=True, null=True) > > def __str__(self): > return self.name > > class SubSection(models.Model): > class Meta: > ordering = ['pk'] > > section = models.ForeignKey( > Section, related_name='sub_sections', on_delete=models.CASCADE) > name = models.CharField(max_length=120) > goal = models.TextField(max_length=500, default='', blank=True, null=True) > image = models.FileField(upload_to=upload_path, null=True, blank=True, > validators=[ > FileExtensionValidator(allowed_extensions=['jpg', 'png', 'jpeg'])]) > link = models.URLField(max_length=200, null=True, blank=True) > created_date = models.DateTimeField(auto_now_add=True) > order_list = models.CharField(max_length=500, validators=[ > int_list_validator], blank=True, null=True) > is_homework = models.BooleanField(default=False) > > materials = GenericRelation( > "Material", null=True, related_query_name='sub_section') > > comments = GenericRelation( > "Comment", null=True, related_query_name='sub_sections') > point = models.PositiveSmallIntegerField(default=0) > skills = models.ManyToManyField(Skill) > hours = models.PositiveIntegerField(default=0, blank=True) > > def __str__(self): > return self.name > > def get_absolute_url(self): > return reverse("sub_section", kwargs={"course_pk": self.section.course.pk, > "section_pk": self.section.pk, "sub_section_pk": self.pk}) > > class Step(models.Model): > class Meta: > ordering = ['pk'] > > TEXT = 1 > HINT = 2 > TEST = 3 > EXERCISE = 4 > CODE_EXAMPLE = 5 > MODELING_3D = 6 > VIDEO = 7 > MATERIALS = 8 > > TYPE_CHOICES = ( > (TEXT, 'Текст'), > (HINT, 'Подсказка'), > (TEST, 'Тестовое задание'), > (EXERCISE, 'Упражнение для программирование'), > (CODE_EXAMPLE, 'Пример кода'), > (MODELING_3D, 'Пример 3D модели'), > (VIDEO, 'Видео'), > (MATERIALS, 'Материалы'), > ) > > sub_section = models.ForeignKey( > SubSection, related_name='steps',
How to make admin duplicate action for an object with all related foreign key and one-to-one fields?
Hello everyone, I am bit confused about making duplicate of a Course object in admin actions with all related child objects. So my Models are: class Course(models.Model): PROGRAMMING = 1 DESIGN = 2 ROBOTICS = 3 DIGITAL_LITERACY = 4 IT_ENTREPRENEURSHIP = 5 CATEGORY_CHOICES = ( (PROGRAMMING, 'Программирование, IT предпринимательство'), (DESIGN, 'Компьютерная графика и медиа'), (ROBOTICS, 'Робототехника и электроника'), (DIGITAL_LITERACY, 'Компьютерная грамотность'), ) NEW = 1 PROGRESS = 2 READY = 3 STATUS_CHOICES = ( (NEW, 'Новый'), (PROGRESS, 'В прогрессе'), (READY, 'Готово'), ) class Meta: ordering = ['pk'] course_type = models.ForeignKey( Category, related_name='courses', on_delete=models.SET_NULL, blank=True, null=True, db_index=True) name = models.CharField(max_length=120, db_index=True) short_description = models.TextField(blank=True, null=True) description = models.TextField(blank=True, null=True) image = models.FileField(upload_to=upload_path, null=True, blank=True) icon = models.FileField(upload_to=upload_path, null=True, blank=True) video_link = models.URLField(max_length=200, null=True, blank=True) target_audience = models.TextField(blank=True, null=True) price = models.DecimalField(max_digits=8, decimal_places=2, default=0.00, validators=[ MinValueValidator(Decimal('0.00'))], blank=True) author = models.ForeignKey( 'users.User', default=1, on_delete=models.SET_NULL, null=True) language = models.CharField( max_length=3, choices=settings.LANGUAGES, default='ru', db_index=True) category = models.PositiveSmallIntegerField( choices=CATEGORY_CHOICES, default=PROGRAMMING, db_index=True) robotics_kit = models.ForeignKey( RoboticsKit, related_name='courses', on_delete=models.SET_NULL, blank=True, null=True) course_class = models.ManyToManyField( CourseClass, related_name='courses') status = models.PositiveSmallIntegerField( choices=STATUS_CHOICES, default=NEW, blank=True) order_list = models.CharField(max_length=500, validators=[ int_list_validator], blank=True, null=True) created_date = models.DateTimeField(auto_now_add=True) is_accessible = models.BooleanField(default=True, null=True, blank=True) is_intro = models.BooleanField(default=False, null=True, blank=True) projects = models.ManyToManyField( "self", blank=True, related_name='courses') # objects = DefaultSelectOrPrefetchManager( # select_related=('robotics_kit', 'course_class', 'course_type')) def __str__(self): return self.name class Section(models.Model): class Meta: ordering = ['pk'] course = models.ForeignKey( Course, related_name='sections', on_delete=models.CASCADE) name = models.CharField(max_length=120) created_date = models.DateTimeField(auto_now_add=True) order_list = models.CharField(max_length=500, validators=[ int_list_validator], blank=True, null=True) def __str__(self): return self.name class SubSection(models.Model): class Meta: ordering = ['pk'] section = models.ForeignKey( Section, related_name='sub_sections', on_delete=models.CASCADE) name = models.CharField(max_length=120) goal = models.TextField(max_length=500, default='', blank=True, null=True) image = models.FileField(upload_to=upload_path, null=True, blank=True, validators=[ FileExtensionValidator(allowed_extensions=['jpg', 'png', 'jpeg'])]) link = models.URLField(max_length=200, null=True, blank=True) created_date = models.DateTimeField(auto_now_add=True) order_list = models.CharField(max_length=500, validators=[ int_list_validator], blank=True, null=True) is_homework = models.BooleanField(default=False) materials = GenericRelation( "Material", null=True, related_query_name='sub_section') comments = GenericRelation( "Comment", null=True, related_query_name='sub_sections') point = models.PositiveSmallIntegerField(default=0) skills = models.ManyToManyField(Skill) hours = models.PositiveIntegerField(default=0, blank=True) def __str__(self): return self.name def get_absolute_url(self): return reverse("sub_section", kwargs={"course_pk": self.section.course.pk, "section_pk": self.section.pk, "sub_section_pk": self.pk}) class Step(models.Model): class Meta: ordering = ['pk'] TEXT = 1 HINT = 2 TEST = 3 EXERCISE = 4 CODE_EXAMPLE = 5 MODELING_3D = 6 VIDEO = 7 MATERIALS = 8 TYPE_CHOICES = ( (TEXT, 'Текст'), (HINT, 'Подсказка'), (TEST, 'Тестовое задание'), (EXERCISE, 'Упражнение для программирование'), (CODE_EXAMPLE, 'Пример кода'), (MODELING_3D, 'Пример 3D модели'), (VIDEO, 'Видео'), (MATERIALS, 'Материалы'), ) sub_section = models.ForeignKey( SubSection, related_name='steps', on_delete=models.CASCADE) name = models.CharField(blank=True, max_length=255) step_type = models.PositiveSmallIntegerField( choices=TYPE_CHOICES, default=TEXT) materials = GenericRelation( "Material", null=True, related_query_name='step') created_date = models.DateTimeField(auto_now_add=True) class TextLinkFileStep(models.Model): step = models.OneToOneField( Step, related_name='step_text_link_file', on_delete=models.CASCADE, null=True, blank=True) text = models.TextField(blank=True,