Rontim / MyCampus-backend

Backend for the MyCampus project
1 stars 0 forks source link

Include Username in Blog Slug #10

Closed Mirror83 closed 8 months ago

Mirror83 commented 8 months ago

Include the blog username in the slug, so that different authors can have blogs with the same title. Currently, the slug only includes the title of the blogs.

Rontim commented 8 months ago

Okay the logic, in the blog model, there are three fields; author type, author user and author club, so we will check what the other type is and update accordingly and save the slug before creation

def save(self, *args, **kwargs):
    base_slug = self.title
    if self.author_type == "user":
        base_slug += f' {self.author_user.username}'
    if self.author_type == "club":
        base_slug += f' {self.author_club.club_name}'
    self.slug = slugify(base_slug)
    super().save(*args, **kwargs)
Rontim commented 8 months ago

@muceraaa please handle that:

  1. create the branch for this issue
  2. checkout into that branch locally
  3. Happy coding