-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(models) issue-196: add models and endpoints to user wishlist
This commit is the first part of the issue 196 (feature wishlist) This commit add: * model CourseWish that link a User and a Course * endpoints to use this new model, according to the auth User * GET wish list (can be filtered by course_code) * GET a wish * POST a wish * DELETE a wish
- Loading branch information
Showing
10 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Generated by Django 4.0.10 on 2023-02-23 06:39 | ||
|
||
import uuid | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="CourseWish", | ||
fields=[ | ||
( | ||
"id", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
help_text="primary key for the record as UUID", | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="id", | ||
), | ||
), | ||
( | ||
"created_on", | ||
models.DateTimeField( | ||
auto_now_add=True, | ||
help_text="date and time at which a record was created", | ||
verbose_name="created on", | ||
), | ||
), | ||
( | ||
"updated_on", | ||
models.DateTimeField( | ||
auto_now=True, | ||
help_text="date and time at which a record was last updated", | ||
verbose_name="updated on", | ||
), | ||
), | ||
( | ||
"course", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="wished_in_wishlists", | ||
to="core.course", | ||
verbose_name="Course", | ||
), | ||
), | ||
( | ||
"owner", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="wishlists", | ||
to=settings.AUTH_USER_MODEL, | ||
verbose_name="Owner", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Course Wish", | ||
"verbose_name_plural": "Course Wishes", | ||
"db_table": "joanie_course_wish", | ||
"unique_together": {("owner", "course")}, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
from .certifications import * | ||
from .courses import * | ||
from .products import * | ||
from .wishlist import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Declare and configure the models for the wishlist part | ||
""" | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from . import Course, User | ||
from .base import BaseModel | ||
|
||
|
||
class CourseWish(BaseModel): | ||
""" | ||
CourseWish represents and records a user wish to participate at a course | ||
""" | ||
|
||
owner = models.ForeignKey( | ||
to=User, | ||
verbose_name=_("Owner"), | ||
related_name="wishlists", | ||
on_delete=models.PROTECT, | ||
) | ||
|
||
course = models.ForeignKey( | ||
to=Course, | ||
verbose_name=_("Course"), | ||
related_name="wished_in_wishlists", | ||
on_delete=models.PROTECT, | ||
) | ||
|
||
class Meta: | ||
db_table = "joanie_course_wish" | ||
verbose_name = _("Course Wish") | ||
verbose_name_plural = _("Course Wishes") | ||
unique_together = ("owner", "course") | ||
|
||
def __str__(self): | ||
return f"{self.owner}'s wish to participate at the course {self.course}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.