Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting
TIMEWEB
April 30, 2017, 4: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
v
Jan. 17, 2019, 11:51 a.m.
vitalir12

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:20points,
  • Rating points-10
v
Jan. 17, 2019, 11:49 a.m.
vitalir12

C++ - Test 002. Constants

  • Result:50points,
  • Rating points-4
v
Jan. 17, 2019, 11:13 a.m.
vitalir12

C++ - Тест 003. Условия и циклы

  • Result:28points,
  • Rating points-10
Last comments
I
Jan. 16, 2019, 8:06 a.m.
IscanderChe

Заработало. Забыл model->select(); вписать.
I
Jan. 16, 2019, 8:02 a.m.
IscanderChe

Всё равно пусто, хотя строка с данными в базу добавляется.
Jan. 16, 2019, 7:51 a.m.
Евгений Легоцкой

потому, что нужно сохранять информацию для всех остальных ролей и столбцов через вызов переопределённого метода. Да к тому же вы ещё и зациклили вызов метода data. QVariant MySqlTableModel:...
I
Jan. 16, 2019, 7:43 a.m.
IscanderChe

Сделал вот так. В tableView ничего нет, кроме заголовка. QVariant MySqlTableModel::data(const QModelIndex &index, int role) const{ if (role == Qt::DisplayRole) { QTime ...
Now discuss on the forum
Jan. 17, 2019, 1:40 p.m.
Михаиллл

Спасибо, заработало.Учту с переменными.
Jan. 17, 2019, 12:01 p.m.
Алексей Внуков

у меня просто есть отдельное поле с чекбоксамими какие колонки нужно отображать CheckBox { id: checkBox text: qsTr("some text") checked: true onC...
Jan. 15, 2019, 4:53 p.m.
Михаиллл

Спасибо, заработало.Но выдало обычный текст без форатирования HTML.Придется искать дальше
Jan. 15, 2019, 12:52 p.m.
BlinCT

Я же вам выше написал CLion умеет работать с ремоут машинами. И Qt так же собирает.
Join us in social networks

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