Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically save the headline for every new article provided my 3rd party js script is embed on a website

I am working on a something similar to Disqus, and I created a third-party javascript snippet which the user will embed in the website and have a rating widget for each article. Users can rate the article using the widget. Everything is working, the server is making the request, but I am making the article object instance explicitly.

I need to automate this, like for a new article on the website, checking the request is coming from the authenticated website and create a new rating widget in the Database in Django and Django-rest-framework.

I am using Python 2.7.

Question: How do I automatically save the headline of the new article, if its new and authenticated in the database?

I know that I need to use a model to implement this, but I am unsure how to do the actual implementation.

EDIT:

Let's say this is the query

https://example.com/embed/comments/?base=default&version=edb619270a92c3035c453faa7c9444d1&f=example&t_i=article_2431522&t_u=http%3A%2F%2Fwww.firstpost.com%2Fbollywood%2Flatest-trailer-of-spectre-is-out-james-bond-is-back-all-guns-and-cars-blazing-2431522.html%09&t_e=Latest%20trailer%20of%20%27Spectre%27%20is%20out%3A%20James%20Bond%20is%20back%20all%20guns%20and%20cars%20blazing&t_d=Latest%20trailer%20of%20%27Spectre%27%20is%20out%3A%20James%20Bond%20is%20back%20all%20guns%20and%20cars%20blazing&t_t=Latest%20trailer%20of%20%27Spectre%27%20is%20out%3A%20James%20Bond%20is%20back%20all%20guns%20and%20cars%20blazing&s_o=default

In my model I need save the following, like f to forum (where forum=models.CharField("short name", max_length=30, unique=True)

I know I need to parse the url for every &, but don't know how. I checked the documentation of rest-framework, but I didn't get the gist of it.

    `f ---->forum,
    t_i----> identifier,
    t_u----> url 
    t_s----> slug,
    t_e----> title,
    t_d----> documentTitle,
    t_t----> title || documentTitle,
    t_c ---->category,
    s_o----> sortOrder,
    l----> language`

What's the best practice to save? Hope this helps

like image 778
n00b Avatar asked Sep 13 '15 11:09

n00b


1 Answers

I'm going to just answer the question you stated at the end: "How do I automatically save the headline of the new article"

You're right, you'll need to create an Article model that mirrors the 3rd party site's articles.

It'll need to have a field for the title/headline (probably CharField), make sure you make it big enough and/or deal with cases where the title is bigger.

You'll also need a unique ID for each article. Ideally, rather than using Django's default, you'll use whatever the 3rd party site is using as the unique ID as a One to One mapping.

Then whenever a request comes in you can use the get_or_create method to ensure the article exists in your DB.

like image 181
OllyTheNinja Avatar answered Nov 03 '22 01:11

OllyTheNinja