IM
Last visit 1 week, 6 days ago

Igor' Maksimov

chunk

  • 0
  • 0
Jan. 8, 2018, 2:52 a.m.

Django

Django, URL, JavaScript

The less information a site has to transmit to each request, the better. Because we get less load on the server and on the communication channel. The first such improvement on the site I did was loading the list of articles when navigating the page paginator.

The point is that when the user wants to go to the next page with a list of articles and clicks on the link in the paginator , the click event is intercepted, the event is canceled, but the AJAX request is sent to the server with the number of the requested page. When the server receives such a request, it only renders the list of articles and sends it back.

May 10, 2017, 12:38 p.m.

Django

AJAX, Django, Polling

Frequent surveys with AJAX allow you to establish a permanent connection between the browser and the server in order to update any data, for example, whether there are new notifications on the site for the user. For example, I organized a small system of notifications for registered users, which allows them to find out at the entrance to the site if there were answers in the articles and forum questions to which they are subscribed, and whether there were new articles and questions on the forum, to sections of which users were also signed.

The notifications are as follows:

April 30, 2017, 12:17 p.m.

Django

Like, Django, GenericRelation, Dislike, GenericForeignKey

In the article on creating a system of bookmarks on Django, an example was considered with the use of an abstract model for several types of bookmarks, namely for articles and comments on articles. Attention was also drawn to the fact that the model fields that had foreign keys to different models should have the same names to support the possibility of creating a single interface for adding bookmarks. This is made possible by the so-called "duck typing", which implies that objects that do not have a single inheritance hierarchy can be used in the same scenario if there are interfaces (methods) that have the same signature.

Literally the principle of duck typing sounds like this:

If it looks like a duck, swims like a duck and quacks like a duck, then it probably is a duck.

That is, having methods with the same signature, we can use objects that are not associated with an inheritance hierarchy, in the same context.

In the same article, let's consider the variant when using the Like Dislike system, not two different tables for articles and comments are used, and not even one that will contain a foreign key for an article or comment (that is, two columns, One of the columns, depending on what type of content the user activity is related to), and one table that will contain:

  • content_type - The content type to which the record belongs
  • object_id - Record ID
    • content_object - The generated foreign key to write, in fact the content object
  • Other additional fields
April 8, 2017, 7:52 a.m.

Django

bookmark, AJAX, favorite, Django, jQuery

The site has the ability to mark articles, comments, topics and answers on the forum as favorites. However, marking as favorites does not provide a reload of the page, because for these actions the mechanism of AJAX-requests is used.

In order to implement the bookmark system, you need:

  • Add a table that implements the Many-to-Many relationship between the user and the article or comment.
  • Add a view that will handle this request.
  • Add url to handle the request to add or exclude an object from the favorites.
  • Write the html-code, which will be responsible for displaying the counter added to the bookmark.
  • Add a javascript handler that will call the AJAX request.

On this site, the icon of the star from Bootstrap is used as a counter icon.

Looking for a Job?
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising