Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MOOC packages by hacklab
django-courses
Commits
b0ef725d
Commit
b0ef725d
authored
Feb 02, 2021
by
Matheus Miranda
Browse files
Add model CourseCategory
parent
a222d76b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
courses/migrations/0018_auto_20210202_1655.py
courses/migrations/0018_auto_20210202_1655.py
+31
-0
courses/models.py
courses/models.py
+13
-0
No files found.
courses/migrations/0018_auto_20210202_1655.py
0 → 100644
View file @
b0ef725d
# Generated by Django 2.2.17 on 2021-02-02 19:55
import
autoslug.fields
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'courses'
,
'0017_course_course_load'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'CourseCategory'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'name'
,
models
.
CharField
(
max_length
=
124
,
verbose_name
=
'title'
)),
(
'slug'
,
autoslug
.
fields
.
AutoSlugField
(
editable
=
False
,
populate_from
=
'name'
,
unique
=
True
)),
(
'description'
,
models
.
TextField
(
blank
=
True
,
verbose_name
=
'description'
)),
(
'color'
,
models
.
CharField
(
blank
=
True
,
help_text
=
'Title color in hex format (i.e: #1aafd0).'
,
max_length
=
7
,
verbose_name
=
'color'
)),
(
'parent'
,
models
.
ForeignKey
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'courses.CourseCategory'
,
verbose_name
=
'course category parent'
)),
],
),
migrations
.
AddField
(
model_name
=
'course'
,
name
=
'category'
,
field
=
models
.
ManyToManyField
(
blank
=
True
,
to
=
'courses.CourseCategory'
,
verbose_name
=
'category'
),
),
]
courses/models.py
View file @
b0ef725d
...
...
@@ -27,6 +27,18 @@ from .classroom.models import Classroom, Event
import
re
class
CourseCategory
(
models
.
Model
):
parent
=
models
.
ForeignKey
(
'self'
,
models
.
CASCADE
,
verbose_name
=
_
(
"course category parent"
),
null
=
True
,
blank
=
True
)
name
=
models
.
CharField
(
_
(
"title"
),
max_length
=
124
)
slug
=
AutoSlugField
(
populate_from
=
"name"
,
unique
=
True
)
description
=
models
.
TextField
(
_
(
"description"
),
blank
=
True
)
color
=
models
.
CharField
(
_
(
"color"
),
max_length
=
7
,
blank
=
True
,
help_text
=
_
(
"Title color in hex format (i.e: #1aafd0)."
))
def
__str__
(
self
):
return
self
.
name
class
Course
(
models
.
Model
):
STATES
=
(
(
'draft'
,
_
(
'Draft'
)),
...
...
@@ -159,6 +171,7 @@ class Course(models.Model):
null
=
True
,
blank
=
True
,
)
category
=
models
.
ManyToManyField
(
CourseCategory
,
verbose_name
=
_
(
'category'
),
blank
=
True
)
class
Meta
:
verbose_name
=
_
(
'Course'
)
...
...
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