At this stage, I am at the SQL tables step
/* Table : Famille_Article */
CREATE TABLE [Famille_Article] (
[ID_CLASSFAMILLE] VARCHAR(2) PRIMARY KEY,
[LB_FAMILLEARTICLE] TEXT NOT NULL
);
/* Table : Article */
CREATE TABLE IF NOT EXISTS [Article] (
[ID_REFERENCE] VARCHAR(11) PRIMARY KEY,
[DATEINREFERENCE] DATE NOT NULL,
[ID_SRCFILEARTICLE] CHAR(1) NOT NULL,
[DESIGNATION] VARCHAR(500) NOT NULL,
[DATENDREFERENCE] DATE,
[ID_CLASSFAMILLE] VARCHAR(2) NOT NULL,
[INFORMATION] TEXT NULL,
FOREIGN KEY (ID_SRCFILEARTICLE) REFERENCES T_Src_File_Article(ID_SRCFILEARTICLE)
FOREIGN KEY (ID_CLASSFAMILLE) REFERENCES Famille_Article(ID_CLASSFAMILLE)
);
/* Table : SRCFILEARTICLE */
CREATE TABLE [T_Src_File_Article] (
[ID_SRCFILEARTICLE] CHAR PRIMARY KEY,
[SRCFILEARTICLE_COMMENT] VARCHAR(10) NOT NULL UNIQUE,
[SRCFILEARTICLE_DESCR] TEXT NOT NULL
);
/* Table : Prix_Article_Imporateur */
CREATE TABLE [Prix_Article_Imporateur] (
[ID_PRIXIMPORT] TEXT PRIMARY KEY, /*YEAR+COUNT*/
[DATE_PRIXIMPORT] DATE NOT NULL,
[ID_REFERENCE] VARCHAR(11) NOT NULL,
[ANC_PRIXIMPORT] REAL,
[NOUV_PRIXIMPORT] REAL,
[ID_SRCFILEARTICLE] CHAR(1) NOT NULL,
FOREIGN KEY (ID_SRCFILEARTICLE) REFERENCES T_Src_File_Article(ID_SRCFILEARTICLE)
FOREIGN KEY (ID_REFERENCE) REFERENCES Article(ID_REFERENCE)
);
-- ============================================================
-- TRIGGER : Prix_Article_Imporateur_Index
-- ============================================================
CREATE TRIGGER IF NOT EXISTS increment_counter_and_set_prix_article_importateur_id
AFTER INSERT ON Prix_Article_Imporateur
FOR EACH ROW
BEGIN
UPDATE Prix_Article_Imporateur
SET ID_PRIXIMPORT = (SELECT strftime('%Y', 'now') || printf('%08d', ifnull(max(cast(substr(ID_PRIXIMPORT,5) as integer)),0)+1) FROM Prix_Article_Imporateur WHERE substr(ID_PRIXIMPORT,1,4) = strftime('%Y', 'now'))
WHERE rowid=NEW.rowid;
END;
/* Table : Prix_Article_Client */
CREATE TABLE [Prix_Article_Client] (
[ID_PRIXCLIENT] TEXT PRIMARY KEY, /*YEAR+COUNT*/
[DATE_PRIXCLIENT] DATE NOT NULL,
[ID_REFERENCE] VARCHAR(11) NOT NULL,
[ANC_PRIXCLIENT] REAL,
[NOUV_PRIXCLIENT] REAL,
[ID_SRCFILEARTICLE] CHAR(1) NOT NULL,
FOREIGN KEY (ID_SRCFILEARTICLE) REFERENCES T_Src_File_Article(ID_SRCFILEARTICLE)
FOREIGN KEY (ID_REFERENCE) REFERENCES Article(ID_REFERENCE)
);
-- ============================================================
-- TRIGGER : Prix_Article_Client_Index
-- ============================================================
CREATE TRIGGER IF NOT EXISTS increment_counter_and_set_prix_article_client_id
AFTER INSERT ON [Prix_Article_Client]
FOR EACH ROW
BEGIN
UPDATE [Prix_Article_Client]
SET ID_PRIXCLIENT = (SELECT strftime('%Y', 'now') || printf('%08d',
ifnull(max(cast(substr(ID_PRIXCLIENT,5) as integer)),0)+1) FROM
Prix_Article_Client WHERE substr(ID_PRIXCLIENT,1,4) = strftime('%Y', 'now'))
WHERE rowid=NEW.rowid;
END;
Here is the model I created from the command:
python manage.py inspectdb > models.py
class Article(models.Model):
id_reference = models.CharField(db_column='ID_REFERENCE', primary_key=True, blank=True, null=True) # Field name made lowercase.
dateinreference = models.DateField(db_column='DATEINREFERENCE') # Field name made lowercase.
id_srcfilearticle = models.ForeignKey('TSrcFileArticle', models.DO_NOTHING, db_column='ID_SRCFILEARTICLE') # Field name made lowercase.
designation = models.CharField(db_column='DESIGNATION') # Field name made lowercase.
datendreference = models.DateField(db_column='DATENDREFERENCE', blank=True, null=True) # Field name made lowercase.
id_classfamille = models.ForeignKey('FamilleArticle', models.DO_NOTHING, db_column='ID_CLASSFAMILLE') # Field name made lowercase.
information = models.TextField(db_column='INFORMATION', blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'Article'
class FamilleArticle(models.Model):
id_classfamille = models.CharField(db_column='ID_CLASSFAMILLE', primary_key=True, blank=True, null=True) # Field name made lowercase.
lb_famillearticle = models.TextField(db_column='LB_FAMILLEARTICLE') # Field name made lowercase.
class Meta:
managed = False
db_table = 'Famille_Article'
class PrixArticleClient(models.Model):
id_prixclient = models.TextField(db_column='ID_PRIXCLIENT', primary_key=True, blank=True, null=True) # Field name made lowercase.
date_prixclient = models.DateField(db_column='DATE_PRIXCLIENT') # Field name made lowercase.
id_reference = models.ForeignKey(Article, models.DO_NOTHING, db_column='ID_REFERENCE') # Field name made lowercase.
anc_prixclient = models.FloatField(db_column='ANC_PRIXCLIENT', blank=True, null=True) # Field name made lowercase.
nouv_prixclient = models.FloatField(db_column='NOUV_PRIXCLIENT', blank=True, null=True) # Field name made lowercase.
id_srcfilearticle = models.ForeignKey('TSrcFileArticle', models.DO_NOTHING, db_column='ID_SRCFILEARTICLE') # Field name made lowercase.
class Meta:
managed = False
db_table = 'Prix_Article_Client'
class PrixArticleImporateur(models.Model):
id_priximport = models.TextField(db_column='ID_PRIXIMPORT', primary_key=True, blank=True, null=True) # Field name made lowercase.
date_priximport = models.DateField(db_column='DATE_PRIXIMPORT') # Field name made lowercase.
id_reference = models.ForeignKey(Article, models.DO_NOTHING, db_column='ID_REFERENCE') # Field name made lowercase.
anc_priximport = models.FloatField(db_column='ANC_PRIXIMPORT', blank=True, null=True) # Field name made lowercase.
nouv_priximport = models.FloatField(db_column='NOUV_PRIXIMPORT', blank=True, null=True) # Field name made lowercase.
id_srcfilearticle = models.ForeignKey('TSrcFileArticle', models.DO_NOTHING, db_column='ID_SRCFILEARTICLE') # Field name made lowercase.
class Meta:
managed = False
db_table = 'Prix_Article_Imporateur'
class TSrcFileArticle(models.Model):
id_srcfilearticle = models.CharField(db_column='ID_SRCFILEARTICLE', primary_key=True, blank=True, null=True) # Field name made lowercase.
srcfilearticle_comment = models.CharField(db_column='SRCFILEARTICLE_COMMENT') # Field name made lowercase.
srcfilearticle_descr = models.TextField(db_column='SRCFILEARTICLE_DESCR') # Field name made lowercase.
class Meta:
managed = False
db_table = 'T_Src_File_Article'
You can notice that the triggers are not imported into the models.py
file.My goal is to obtain the following query:
Example1
ID_REFERENCE |
DATEINREFERENCE |
ID_SRCFILEARTICLE |
DESIGNATION |
83302356857 |
2024-02-15 |
N |
SUPPORT MODULHEBER HV |
83302356858 |
2024-05-15 |
U |
DISPOSTIF MODULHEBER |
83302356943 |
2024-02-15 |
N |
CLÉ HAKEN A-D |
83302356945 |
2024-05-15 |
N |
MESSHILFE LASER |
Example2:
ID_PRIXIMPORT |
DATE_PRIXIMPORT |
ID_REFERENCE |
ANC_PRIXIMPORT |
NOUV_PRIXIMPORT |
ID_SRCFILEARTICLE |
202400039005 |
2024-02-15 |
71245B3BB76 |
12.95 |
12.69 |
|
202400039006 |
2024-02-15 |
71245B3BB76 |
12.69 |
12.69 |
|
202400039007 |
2024-02-15 |
71245B3BB77 |
8.32 |
8.16 |
|
202400039008 |
2024-02-15 |
71245B3BB77 |
8.16 |
8.16 |
|