1

I am working on a project similar to github, but instead of programming it has to do with language learning. The backend I am using is Django.

How the process will work:

User A submits a post -> other users can see submitted post -> user B decides he wants to correct user A's post -> user B clicks on user A's post -> user A's post is then broken up into individual sentences where each sentence is on a new line -> user B decides which sentence needs fixing -> once done, the changes are highlighted in green while deletions are striked out.

It would be similar to something like this: enter image description here

My current model is set up as so:

class Post(models.Model):
    user = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    title = models.CharField(max_length=200)
    text = models.TextField()
    ...


class Corrections(models.Model):
     user = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
     post = models.ForeignKey(Post, on_delete=models.CASCADE)
     text = models.TextField(null=True)
     ...

Sentence splitting

I believe I should split these using regex to capture the "." then split()?

Problem

Since django cannot natively do this, I figure I would need a js library to accomplish this. I have no experience with js, so if possible can you outline the steps needed to accomplish this? How difficult would something like this be for a beginner? would using a framework for this be a good idea? Is there a library I can use to accomplish this (i tried searching, but no hits)?

Thank you for your time.

Mike
  • 190
  • 12
  • 2
    What do you mean by "Since django cannot natively do this"? Django is just a web framework, but you can of course do this (anything you want) in python. You need to clarify what you want exactly as right now, you 're just stating an end requirement. Start thinking of the steps involved one by one to narrow your problem to smaller problems. – dirkgroten Feb 20 '19 at 12:31

1 Answers1

1

If you can do the comparison on the backend you could use python difflib like here: https://stackoverflow.com/a/788780/2099689

In javascript you could use this library: https://github.com/google/diff-match-patch

  • I finally got that working! How would I go about running this python script in django? Would I have to create a view? Can I directly change and store corrected text in the model? – Mike Feb 20 '19 at 22:34
  • Yes, you would need a view to run the difflib functions and to access and store models. – Frederik Højlund Feb 21 '19 at 12:10