video player and model and video guide routing and stuff
This commit is contained in:
+33
-4
@@ -1,14 +1,15 @@
|
||||
from django.contrib import admin
|
||||
from .models import *
|
||||
from unfold.admin import ModelAdmin
|
||||
from unfold.admin import ModelAdmin as UnfoldModelAdmin
|
||||
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from unfold.contrib.import_export.forms import ExportForm, ImportForm, SelectableFieldsExportForm
|
||||
from unfold.contrib.forms.widgets import ArrayWidget, WysiwygWidget
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
|
||||
|
||||
|
||||
from unfold.decorators import action, display
|
||||
from django.utils.html import format_html
|
||||
from unfold.decorators import display
|
||||
from utils.admin import ModelAdmin
|
||||
@admin.register(ShowCaseSlider)
|
||||
class ShowCaseSliderAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
import_form_class = ImportForm
|
||||
@@ -24,6 +25,34 @@ class ShowCaseSliderAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
}
|
||||
}
|
||||
|
||||
@admin.register(LearnVideoModel)
|
||||
class LearnVideoAdmin(UnfoldModelAdmin):
|
||||
list_display = ['title', 'section', 'display_viewd']
|
||||
search_fields = ['title', 'section']
|
||||
compressed_fields = False
|
||||
list_filter = ['section']
|
||||
warn_unsaved_form = True
|
||||
change_form_template = 'video_change_form_after.html'
|
||||
formfield_overrides = {
|
||||
ArrayField: {
|
||||
"widget": ArrayWidget,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@display(description='دیده شده')
|
||||
def display_viewd(self, instance):
|
||||
if instance.viewd:
|
||||
svg = f'<a href="/home/video/view/{instance.id}"><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 24 24"><path fill="green" d="M12 16q1.875 0 3.188-1.312T16.5 11.5t-1.312-3.187T12 7T8.813 8.313T7.5 11.5t1.313 3.188T12 16m0-1.8q-1.125 0-1.912-.788T9.3 11.5t.788-1.912T12 8.8t1.913.788t.787 1.912t-.787 1.913T12 14.2m0 4.8q-3.65 0-6.65-2.037T1 11.5q1.35-3.425 4.35-5.462T12 4t6.65 2.038T23 11.5q-1.35 3.425-4.35 5.463T12 19m0-2q2.825 0 5.188-1.487T20.8 11.5q-1.25-2.525-3.613-4.012T12 6T6.813 7.488T3.2 11.5q1.25 2.525 3.613 4.013T12 17"/></svg></a>'
|
||||
else:
|
||||
svg = f'<a href="/home/video/view/{instance.id}"><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 24 24"><path fill="#c30009" d="m19.1 21.9l-3.5-3.45q-.875.275-1.775.413T12 19q-3.35 0-6.125-1.8t-4.35-4.75q-.125-.225-.187-.462t-.063-.488t.063-.488t.187-.462q.55-.975 1.175-1.9T4.15 7L2.075 4.9Q1.8 4.625 1.8 4.213t.3-.713q.275-.275.7-.275t.7.275l17 17q.275.275.288.688t-.288.712q-.275.275-.7.275t-.7-.275M12 16q.275 0 .525-.025t.5-.1l-5.4-5.4q-.075.25-.1.5T7.5 11.5q0 1.875 1.313 3.188T12 16m0-12q3.35 0 6.138 1.813t4.362 4.762q.125.2.188.438t.062.487t-.05.488t-.175.437q-.475.925-1.062 1.75t-1.313 1.55q-.35.35-.825.325t-.825-.375l-2-2q-.175-.175-.225-.413t.025-.487q.1-.325.15-.625t.05-.65q0-1.875-1.312-3.187T12 7q-.35 0-.65.05t-.625.15q-.25.075-.5.025T9.8 7l-.825-.825q-.475-.475-.312-1.1t.787-.8q.625-.125 1.263-.2T12 4m1.975 5.65q.275.325.462.713t.238.812q.025.2-.15.275t-.325-.075l-2.05-2.05Q12 9.175 12.088 9t.287-.175q.475.05.875.263t.725.562"/></svg></a>'
|
||||
|
||||
return format_html(
|
||||
svg
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@admin.register(SliderModel)
|
||||
class SliderAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-14 21:23
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('home', '0005_alter_showcaseslider_description_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='LearnVideoModel',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=50)),
|
||||
('video', models.FileField(upload_to='learning_video/')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'ویدیوی اموزشی',
|
||||
'verbose_name_plural': 'ویدیوی های اموزشی',
|
||||
},
|
||||
),
|
||||
]
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-14 21:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('home', '0006_learnvideomodel'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='learnvideomodel',
|
||||
name='section',
|
||||
field=models.CharField(default='', max_length=40, verbose_name='بخش مربوطه'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='learnvideomodel',
|
||||
name='title',
|
||||
field=models.CharField(max_length=100, verbose_name='عنوان ویدیو'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='learnvideomodel',
|
||||
name='video',
|
||||
field=models.FileField(upload_to='learning_video/', verbose_name='ویدیو'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-14 23:12
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0002_remove_content_type_name'),
|
||||
('home', '0007_learnvideomodel_section_alter_learnvideomodel_title_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='learnvideomodel',
|
||||
name='content_type',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', verbose_name='Related Model'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-14 23:28
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0002_remove_content_type_name'),
|
||||
('home', '0008_learnvideomodel_content_type'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='learnvideomodel',
|
||||
name='content_type',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', unique=True, verbose_name='مدل مرتبط'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-15 00:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('home', '0009_alter_learnvideomodel_content_type'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='learnvideomodel',
|
||||
name='viewd',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-15 07:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('home', '0010_learnvideomodel_viewd'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='learnvideomodel',
|
||||
name='icon',
|
||||
field=models.CharField(default='', max_length=30, verbose_name='ایکون'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='learnvideomodel',
|
||||
name='viewd',
|
||||
field=models.BooleanField(default=False, verbose_name='تماشا شده'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-16 17:45
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0002_remove_content_type_name'),
|
||||
('home', '0011_learnvideomodel_icon_alter_learnvideomodel_viewd'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='learnvideomodel',
|
||||
name='content_type',
|
||||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', verbose_name='مدل مرتبط'),
|
||||
),
|
||||
]
|
||||
+36
-2
@@ -1,6 +1,6 @@
|
||||
from django.db import models
|
||||
from product.models import ProductModel
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
class SliderModel(models.Model):
|
||||
link = models.URLField(verbose_name='لینک')
|
||||
@@ -45,4 +45,38 @@ class ShowCaseSlider(models.Model):
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'مدل نمایش کیس'
|
||||
verbose_name_plural = 'مدل نمایش کیس ها'
|
||||
verbose_name_plural = 'مدل نمایش کیس ها'
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
class LearnVideoModel(models.Model):
|
||||
title = models.CharField(max_length=100, verbose_name='عنوان ویدیو')
|
||||
section = models.CharField(max_length=40, verbose_name='بخش مربوطه')
|
||||
video = models.FileField(upload_to='learning_video/', verbose_name='ویدیو')
|
||||
content_type = models.OneToOneField(
|
||||
ContentType,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name='مدل مرتبط', blank=True, null=True, unique=True
|
||||
)
|
||||
icon = models.CharField(max_length=30, verbose_name='ایکون')
|
||||
viewd = models.BooleanField(default=False, verbose_name='تماشا شده')
|
||||
@property
|
||||
def section_url(self):
|
||||
if not self.content_type:
|
||||
return None
|
||||
|
||||
app_label = self.content_type.app_label
|
||||
model_name = self.content_type.model
|
||||
|
||||
try:
|
||||
return reverse(f'admin:{app_label}_{model_name}_changelist')
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'ویدیوی اموزشی'
|
||||
verbose_name_plural = 'ویدیوی های اموزشی'
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('video/view/<int:pk>', views.ChangeViewVideo.as_view(), name='product-chat-view'),
|
||||
]
|
||||
+10
-1
@@ -1,10 +1,19 @@
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from rest_framework.views import APIView, Response
|
||||
from product.models import ProductModel, SubCategoryModel, DollorModel
|
||||
from product.serializers import SubCategorySerializer, DynamicProductSerializer
|
||||
from .serializers import *
|
||||
from .models import *
|
||||
from rest_framework import status
|
||||
from django.views import View
|
||||
|
||||
|
||||
class ChangeViewVideo(View):
|
||||
def get(self, request, pk):
|
||||
videomodel = get_object_or_404(LearnVideoModel, pk=pk)
|
||||
videomodel.viewd = not videomodel.viewd
|
||||
videomodel.save()
|
||||
return redirect('admin:home_learnvideomodel_changelist')
|
||||
|
||||
|
||||
class HomeView(APIView):
|
||||
|
||||
Reference in New Issue
Block a user