Skip to content

Commit

Permalink
add readable_id to bootcamp model and related changes (#1507)
Browse files Browse the repository at this point in the history
* add readable_id to bootcamp model and related changes

* update migration script

* update to use f string
  • Loading branch information
rachellougee authored Apr 10, 2024
1 parent 0c01b06 commit 5fb63c6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 3 deletions.
10 changes: 8 additions & 2 deletions klasses/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ class BootcampAdmin(admin.ModelAdmin):
"""Admin for Bootcamp"""

model = models.Bootcamp
list_display = ("title",)
search_fields = ("title",)
list_display = (
"title",
"readable_id",
)
search_fields = (
"title",
"readable_id",
)
inlines = [BootcampRunInline]


Expand Down
3 changes: 3 additions & 0 deletions klasses/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class BootcampFactory(DjangoModelFactory):
"""Factory for Bootcamp"""

title = FuzzyText(prefix="Bootcamp ")
readable_id = LazyAttribute(
lambda x: f"bootcamp-v1:{ random.choice(['public', 'private']) }+{FAKE.slug()}-{random.choice(['ol', 'f2f'])}"
)

class Meta:
model = models.Bootcamp
Expand Down
25 changes: 25 additions & 0 deletions klasses/migrations/0029_bootcamp_readable_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.25 on 2024-04-05 16:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("klasses", "0028_add_early_bird_deadline"),
]

operations = [
migrations.AddField(
model_name="bootcamp",
name="readable_id",
field=models.CharField(
blank=True,
max_length=255,
null=True,
unique=True,
help_text="The unique string to identify this bootcamp. It can be of the form "
"'bootcamp-v1:TYPE+TOPIC-FORMAT' (example: bootcamp-v1:public+IE-f2f)",
),
),
]
8 changes: 8 additions & 0 deletions klasses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class Bootcamp(models.Model):

title = models.TextField()
legacy = models.BooleanField(default=False)
readable_id = models.CharField(
null=True,
blank=True,
unique=True,
max_length=255,
help_text="The unique string to identify this bootcamp. It can be of the form 'bootcamp-v1:TYPE+TOPIC-FORMAT'"
"(example: bootcamp-v1:public+IE-f2f)",
)

def __str__(self):
return "Bootcamp {title}".format(title=self.title)
Expand Down
2 changes: 1 addition & 1 deletion klasses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BootcampSerializer(serializers.ModelSerializer):

class Meta:
model = Bootcamp
fields = ["id", "title"]
fields = ["id", "title", "readable_id"]


class BootcampRunSerializer(serializers.ModelSerializer):
Expand Down
1 change: 1 addition & 0 deletions klasses/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_bootcamp_serializer():
assert BootcampSerializer(bootcamp).data == {
"title": bootcamp.title,
"id": bootcamp.id,
"readable_id": bootcamp.readable_id,
}


Expand Down
3 changes: 3 additions & 0 deletions localdev/seed/resources/seed_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"bootcamps": [
{
"title": "Single Variable Calculus",
"readable_id": "bootcamp-v1:public+SVCR-ol",
"[runs]": [
{
"title": "Single Variable Calculus Run 1",
Expand Down Expand Up @@ -32,6 +33,7 @@
},
{
"title": "Multivariable Calculus",
"readable_id": "bootcamp-v1:private+MCR-f2f",
"[runs]": [
{
"title": "Multivariable Calculus Run 1",
Expand Down Expand Up @@ -72,6 +74,7 @@
},
{
"title": "Differential Equations",
"readable_id": "bootcamp-v1:public+DER-f2f",
"[runs]": [
{
"title": "Differential Equations Run 1",
Expand Down

0 comments on commit 5fb63c6

Please sign in to comment.