Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
C
cp_video_dokku
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandr Dzehil
cp_video_dokku
Commits
47a56d37
Commit
47a56d37
authored
Mar 06, 2023
by
Ilya Simonov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tags models
parent
3d63ed0e
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
106 additions
and
2 deletions
+106
-2
.gitignore
.gitignore
+1
-1
admin.cpython-39.pyc
apps/core/__pycache__/admin.cpython-39.pyc
+0
-0
models.cpython-39.pyc
apps/core/__pycache__/models.cpython-39.pyc
+0
-0
admin.py
apps/core/admin.py
+23
-0
0002_category_tag_alter_video_options_and_more.py
...rations/0002_category_tag_alter_video_options_and_more.py
+38
-1
0002_category_video_closed_captions_video_creator_and_more.cpython-39.pyc
...deo_closed_captions_video_creator_and_more.cpython-39.pyc
+0
-0
models.py
apps/core/models.py
+44
-0
No files found.
.gitignore
View file @
47a56d37
...
...
@@ -21,7 +21,7 @@ Thumbs.db
.redis-stable
# Python
__pycache__
__pycache__
/
*.pyc
# Development
...
...
apps/core/__pycache__/admin.cpython-39.pyc
View file @
47a56d37
No preview for this file type
apps/core/__pycache__/models.cpython-39.pyc
View file @
47a56d37
No preview for this file type
apps/core/admin.py
View file @
47a56d37
from
django.contrib
import
admin
from
django.contrib.contenttypes.admin
import
GenericTabularInline
from
.
import
models
class
TagAdmin
(
admin
.
ModelAdmin
):
list_display
=
[
'id'
,
'name'
]
search_fields
=
[
'name'
]
class
TagToObjectAdmin
(
admin
.
ModelAdmin
):
list_display
=
[
'id'
,
'tag'
,
'object_id'
,
'content_type'
]
search_fields
=
[
'tag__name'
,
'object_id'
,
'content_type__name'
]
autocomplete_fields
=
[
'tag'
]
class
TagInline
(
GenericTabularInline
):
model
=
models
.
TagToObject
autocomplete_fields
=
[
'tag'
]
extra
=
0
verbose_name
=
'Tag'
classes
=
[
'collapse'
]
class
VideoAdmin
(
admin
.
ModelAdmin
):
list_display
=
[
'id'
,
'title'
,
'slug'
,
'status'
,
'duration'
]
readonly_fields
=
[
'created'
,
'updated'
]
list_filter
=
(
'status'
,)
inlines
=
[
TagInline
]
def
save_model
(
self
,
request
,
obj
,
form
,
change
):
obj
.
creator
=
request
.
user
...
...
@@ -25,3 +46,5 @@ class CategoryAdmin(admin.ModelAdmin):
admin
.
site
.
register
(
models
.
Video
,
VideoAdmin
)
admin
.
site
.
register
(
models
.
Playlist
,
PlayListAdmin
)
admin
.
site
.
register
(
models
.
Category
,
CategoryAdmin
)
admin
.
site
.
register
(
models
.
Tag
,
TagAdmin
)
admin
.
site
.
register
(
models
.
TagToObject
,
TagToObjectAdmin
)
apps/core/migrations/0002_category_
video_closed_captions_video_creator
_and_more.py
→
apps/core/migrations/0002_category_
tag_alter_video_options
_and_more.py
View file @
47a56d37
# Generated by Django 4.1.7 on 2023-03-06 1
4:07
# Generated by Django 4.1.7 on 2023-03-06 1
6:31
import
apps.core.utils
from
django.conf
import
settings
...
...
@@ -11,6 +11,7 @@ class Migration(migrations.Migration):
dependencies
=
[
migrations
.
swappable_dependency
(
settings
.
AUTH_USER_MODEL
),
(
'contenttypes'
,
'0002_remove_content_type_name'
),
(
'core'
,
'0001_initial'
),
]
...
...
@@ -21,6 +22,27 @@ class Migration(migrations.Migration):
(
'id'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'name'
,
models
.
CharField
(
db_index
=
True
,
max_length
=
255
,
verbose_name
=
'name'
)),
],
options
=
{
'verbose_name'
:
'Category'
,
'verbose_name_plural'
:
'Categories'
,
'ordering'
:
(
'name'
,),
},
),
migrations
.
CreateModel
(
name
=
'Tag'
,
fields
=
[
(
'id'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'name'
,
models
.
CharField
(
db_index
=
True
,
max_length
=
255
,
verbose_name
=
'name'
)),
],
options
=
{
'verbose_name'
:
'Tag'
,
'verbose_name_plural'
:
'Tags'
,
'ordering'
:
(
'name'
,),
},
),
migrations
.
AlterModelOptions
(
name
=
'video'
,
options
=
{
'ordering'
:
(
'title'
,),
'verbose_name'
:
'Video'
,
'verbose_name_plural'
:
'Videos'
},
),
migrations
.
AddField
(
model_name
=
'video'
,
...
...
@@ -73,6 +95,19 @@ class Migration(migrations.Migration):
name
=
'title'
,
field
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
'title'
),
),
migrations
.
CreateModel
(
name
=
'TagToObject'
,
fields
=
[
(
'id'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'object_id'
,
models
.
PositiveIntegerField
(
blank
=
True
,
null
=
True
,
verbose_name
=
'object_id'
)),
(
'content_type'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'content_type_tag'
,
to
=
'contenttypes.contenttype'
,
verbose_name
=
'content type'
)),
(
'tag'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'tag'
,
to
=
'core.tag'
)),
],
options
=
{
'verbose_name'
:
'Tag to object'
,
'verbose_name_plural'
:
'Tags to objects'
,
},
),
migrations
.
CreateModel
(
name
=
'Playlist'
,
fields
=
[
...
...
@@ -84,6 +119,8 @@ class Migration(migrations.Migration):
(
'videos'
,
models
.
ManyToManyField
(
related_name
=
'playlist'
,
to
=
'core.video'
)),
],
options
=
{
'verbose_name'
:
'Playlist'
,
'verbose_name_plural'
:
'Playlists'
,
'ordering'
:
(
'title'
,),
},
),
...
...
apps/core/migrations/__pycache__/0002_category_video_closed_captions_video_creator_and_more.cpython-39.pyc
deleted
100644 → 0
View file @
3d63ed0e
File deleted
apps/core/models.py
View file @
47a56d37
from
django.db
import
models
from
django.utils.translation
import
gettext_lazy
as
_
from
django.contrib.auth.models
import
User
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.fields
import
GenericForeignKey
,
GenericRelation
from
pytils.translit
import
slugify
...
...
@@ -27,9 +29,45 @@ class BaseModel(models.Model):
abstract
=
True
class
Tag
(
models
.
Model
):
name
=
models
.
CharField
(
_
(
'name'
),
max_length
=
255
,
db_index
=
True
)
class
Meta
:
ordering
=
(
'name'
,)
verbose_name
=
'Tag'
verbose_name_plural
=
'Tags'
def
__str__
(
self
):
return
self
.
name
class
TagToObject
(
models
.
Model
):
tag
=
models
.
ForeignKey
(
Tag
,
on_delete
=
models
.
CASCADE
,
related_name
=
'tag'
)
content_type
=
models
.
ForeignKey
(
ContentType
,
on_delete
=
models
.
CASCADE
,
related_name
=
'content_type_tag'
,
verbose_name
=
_
(
'content type'
),
)
object_id
=
models
.
PositiveIntegerField
(
_
(
'object_id'
),
blank
=
True
,
null
=
True
)
content_object
=
GenericForeignKey
(
'content_type'
,
'object_id'
)
class
Meta
:
verbose_name
=
'Tag to object'
verbose_name_plural
=
'Tags to objects'
def
__str__
(
self
):
return
str
(
self
.
id
)
class
Category
(
models
.
Model
):
name
=
models
.
CharField
(
'name'
,
max_length
=
255
,
db_index
=
True
)
class
Meta
:
ordering
=
(
'name'
,)
verbose_name
=
'Category'
verbose_name_plural
=
'Categories'
def
__str__
(
self
):
return
self
.
name
...
...
@@ -85,9 +123,12 @@ class Video(BaseModel):
related_name
=
'video'
,
blank
=
True
,
)
tags
=
GenericRelation
(
TagToObject
)
class
Meta
:
ordering
=
(
'title'
,)
verbose_name
=
'Video'
verbose_name_plural
=
'Videos'
def
__str__
(
self
):
return
self
.
title
...
...
@@ -103,9 +144,12 @@ class Playlist(BaseModel):
title
=
models
.
CharField
(
_
(
'title'
),
max_length
=
255
)
description
=
models
.
TextField
(
_
(
'description'
),
blank
=
True
,
null
=
True
)
videos
=
models
.
ManyToManyField
(
Video
,
related_name
=
'playlist'
)
tags
=
GenericRelation
(
TagToObject
)
class
Meta
:
ordering
=
(
'title'
,)
verbose_name
=
'Playlist'
verbose_name_plural
=
'Playlists'
def
__str__
(
self
):
return
self
.
title
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment