Skip to content

Conversation

@GhanshyamJha05
Copy link

This PR adds fork functionality to code snippets, allowing users to create their own versions of existing snippets (similar to GitHub's fork feature for repositories). This enhances collaboration by enabling users to build upon shared code.

Changes Made

  • Model Updates (cab/models.py): Added forked_from field and fork() method to the Snippet model.
  • View Updates (cab/views/snippets.py): Added fork_snippet view for handling fork requests.
  • URL Updates (cab/urls/snippets.py): Added route for /snippets/<id>/fork/.
  • Template Updates (djangosnippets/templates/cab/snippet_detail.html): Added fork button and "Forked from" display.
  • Migration (cab/migrations/0007_add_forked_from.py): Added migration for the new field.
  • Tests (cab/tests/tests.py): Added test_snippet_fork to verify functionality.

How It Works

  • Users can click "Fork" on any snippet (if logged in and not the author).
  • This creates a new snippet with "(forked)" appended to the title, copies all relevant data, and links it back to the original via forked_from.
  • The new snippet is owned by the forking user and can be edited independently.
  • Forked snippets show a "Forked from" link to the original.

Benefits

  • Encourages contribution and code sharing.
  • Improves user engagement on the platform.
  • Aligns with modern code-sharing platforms like GitHub.

Closes #< issue 650>

- Add forked_from field to Snippet model
- Implement fork method and view
- Update templates to show fork button and forked-from info
- Add migration and tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant