[Answered ]-How to edit & save contents from front-end in Django?

2👍

I find it easiest to start with how the data should be stored in a db. Start with a Article model:

def Article(models.Model):
    url = models.UrlField()
    title = models.CharField(max_length=200, blank=True)
    html = models.TextField(blank=True)

Than we want title and html be filled if url is given. Write a signal receiver to handle scraping:

@receiver(pre_save, instance, sender=Article)
def scrape(sender, **kwargs):
    if instance.url and not instance.title and not instance.html:
        data = requests.get(instance.url)
        instance.html = BeautifulSoup(data)
        instance.title = instance.html.title.name

If you add a admin, you’re done. But views to display and update the data are also easy to create:

class ArticleDetailView(DetailView):
    model = Article

class ArticleUpdate(UpdateView):
    model = Article

Note: The code needs some work. You also need to write imports, urls and templates.

Finally: there is nothing wrong with third party apps. I don’t own Python, Django, Requests, Beautiful Soup, etc… Even if this is a learning project, it a good thing to NOT reinvent the wheel. Be as lazy as possible. Use tools that do the job for you.

0👍

  1. find wysiwyg editor like froala, modify field
  2. update with ajax.
  3. check permissions on server side.

Leave a comment