Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Anthony
memopol
Commits
0fd305ae
Commit
0fd305ae
authored
Sep 05, 2016
by
Nicolas Joyard
Browse files
Add ThemeScore model
parent
df2055dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
memopol_themes/migrations/0002_themescore.py
0 → 100644
View file @
0fd305ae
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'memopol_themes'
,
'0001_initial'
),
(
'representatives_positions'
,
'0004_add_kind_score_title'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'ThemeScore'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
(
'score'
,
models
.
FloatField
(
default
=
0
)),
],
options
=
{
'ordering'
:
[
'theme__slug'
],
'db_table'
:
'memopol_themes_themescore'
,
'managed'
:
False
,
},
),
migrations
.
RunSQL
(
"""
CREATE VIEW "memopol_themes_themescore"
AS SELECT
"representatives_representative"."id" AS "representative_id",
"memopol_themes_theme"."id" AS "theme_id",
SUM(COALESCE("scoresource"."score", 0)) AS "score"
FROM
"representatives_representative"
LEFT OUTER JOIN "memopol_themes_theme"
ON 1=1
LEFT OUTER JOIN (
SELECT
"representatives_recommendations_dossierscores"."representative_id" AS "representative_id",
"memopol_themes_theme"."id" AS "theme_id",
"representatives_recommendations_dossierscores"."score" AS "score"
FROM
"representatives_recommendations_dossierscores"
INNER JOIN "memopol_themes_theme_dossiers"
ON "memopol_themes_theme_dossiers"."dossier_id" = "representatives_recommendations_dossierscores"."dossier_id"
INNER JOIN "memopol_themes_theme"
ON "memopol_themes_theme"."id" = "memopol_themes_theme_dossiers"."theme_id"
UNION ALL
SELECT
"representatives_recommendations_votescores"."representative_id" AS "representative_id",
"memopol_themes_theme"."id" AS "theme_id",
"representatives_recommendations_votescores"."score" AS "score"
FROM
"representatives_recommendations_votescores"
INNER JOIN "memopol_themes_theme_proposals"
ON "memopol_themes_theme_proposals"."proposal_id" = "representatives_recommendations_votescores"."proposal_id"
INNER JOIN "memopol_themes_theme"
ON "memopol_themes_theme"."id" = "memopol_themes_theme_proposals"."theme_id"
UNION ALL
SELECT
"representatives_positions_positionscore"."representative_id" AS "representative_id",
"memopol_themes_theme"."id" AS "theme_id",
"representatives_positions_positionscore"."score" AS "score"
FROM
"representatives_positions_positionscore"
INNER JOIN "memopol_themes_theme_positions"
ON "memopol_themes_theme_positions"."position_id" = "representatives_positions_positionscore"."position_id"
INNER JOIN "memopol_themes_theme"
ON "memopol_themes_theme"."id" = "memopol_themes_theme_positions"."theme_id"
) "scoresource"
ON "scoresource"."theme_id" = "memopol_themes_theme"."id"
AND "scoresource"."representative_id" = "representatives_representative"."id"
GROUP BY
"representatives_representative"."id",
"memopol_themes_theme"."id"
"""
),
]
memopol_themes/models.py
View file @
0fd305ae
...
...
@@ -3,6 +3,7 @@ from django.utils.encoding import smart_unicode
from
autoslug
import
AutoSlugField
from
representatives.models
import
Representative
from
representatives_votes.models
import
Dossier
,
Proposal
from
representatives_positions.models
import
Position
...
...
@@ -28,3 +29,15 @@ class ThemeLink(models.Model):
def
__unicode__
(
self
):
return
smart_unicode
(
'%s (%s)'
%
(
self
.
title
,
self
.
link
))
class
ThemeScore
(
models
.
Model
):
representative
=
models
.
ForeignKey
(
Representative
,
related_name
=
'themescores'
)
theme
=
models
.
ForeignKey
(
Theme
,
related_name
=
'themescores'
)
score
=
models
.
FloatField
(
default
=
0
)
class
Meta
:
managed
=
False
ordering
=
[
'theme__slug'
]
db_table
=
'memopol_themes_themescore'
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment