Django - modeling - multi-table reference
SOS - HELP :
I am newbie in django ( I came from PHP (Laravel)):
I need modeling the data :
I have same models they are named Sources like(IOT, Sensosr, Totens, app etc..) each source has your particularity(conection params) and similarity, then I have scans, scans use sources information to execute (store information about execution) and produce activities on hosts.
I need to link activities to sources through scans, so that, when a activity is showed, information about hosts, scans, and source are showed.
I learning about abstract but it not so clear !
@dirkgroten thanks for your time, Im Edited it to be more precise
look this models:
code
class Sensor (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
class Crawler (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
code
They are my Sources Models , where data Activities came from...
then
code
class Scan (models.Model):
creation_date = models.DateTimeField(auto_now=True)
# Here I neet to link with a source, but source could be a Crawler, IOT, Sensor or API model
...fields
class Host (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
class Activities (models.Model):
creation_date = models.DateTimeField(auto_now=True)
host = models.ForeignKey('Host',on_delete='DELETE')
scan = models.ForeignKey('Scan',on_delete='DELETE')
code
When I list to Show a activities I need to show information about scan and where they come from (source)
like (Activity.Host or Activit.Scan.Source.)
In PHP my Scan table had a "source" flag and an ID field, so I knew in which table to fetch the data from the source.
I know this is not the right way so I want to do this well done using ORM.
if you can help me I will be very grateful.
django model modeling
|
show 1 more comment
SOS - HELP :
I am newbie in django ( I came from PHP (Laravel)):
I need modeling the data :
I have same models they are named Sources like(IOT, Sensosr, Totens, app etc..) each source has your particularity(conection params) and similarity, then I have scans, scans use sources information to execute (store information about execution) and produce activities on hosts.
I need to link activities to sources through scans, so that, when a activity is showed, information about hosts, scans, and source are showed.
I learning about abstract but it not so clear !
@dirkgroten thanks for your time, Im Edited it to be more precise
look this models:
code
class Sensor (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
class Crawler (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
code
They are my Sources Models , where data Activities came from...
then
code
class Scan (models.Model):
creation_date = models.DateTimeField(auto_now=True)
# Here I neet to link with a source, but source could be a Crawler, IOT, Sensor or API model
...fields
class Host (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
class Activities (models.Model):
creation_date = models.DateTimeField(auto_now=True)
host = models.ForeignKey('Host',on_delete='DELETE')
scan = models.ForeignKey('Scan',on_delete='DELETE')
code
When I list to Show a activities I need to show information about scan and where they come from (source)
like (Activity.Host or Activit.Scan.Source.)
In PHP my Scan table had a "source" flag and an ID field, so I knew in which table to fetch the data from the source.
I know this is not the right way so I want to do this well done using ORM.
if you can help me I will be very grateful.
django model modeling
Please check How to Ask to learn how to formulate your question in an appropriate way for SO. You need to show us what you're trying to do with code, show us your initial models. Please be more specific.
– dirkgroten
Nov 20 '18 at 16:32
btw: google "django relationship through intermediate model" and you'll find plenty of stuff.
– dirkgroten
Nov 20 '18 at 16:33
@dirkgroten thanks for your time:
– Adilson Santos da Rocha
Nov 20 '18 at 20:32
@dirkgroten I reformulate my question ! thanks
– Adilson Santos da Rocha
Nov 20 '18 at 21:06
You need to use generic relations, as documented here. There's a blog post as a good example.
– dirkgroten
Nov 21 '18 at 10:32
|
show 1 more comment
SOS - HELP :
I am newbie in django ( I came from PHP (Laravel)):
I need modeling the data :
I have same models they are named Sources like(IOT, Sensosr, Totens, app etc..) each source has your particularity(conection params) and similarity, then I have scans, scans use sources information to execute (store information about execution) and produce activities on hosts.
I need to link activities to sources through scans, so that, when a activity is showed, information about hosts, scans, and source are showed.
I learning about abstract but it not so clear !
@dirkgroten thanks for your time, Im Edited it to be more precise
look this models:
code
class Sensor (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
class Crawler (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
code
They are my Sources Models , where data Activities came from...
then
code
class Scan (models.Model):
creation_date = models.DateTimeField(auto_now=True)
# Here I neet to link with a source, but source could be a Crawler, IOT, Sensor or API model
...fields
class Host (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
class Activities (models.Model):
creation_date = models.DateTimeField(auto_now=True)
host = models.ForeignKey('Host',on_delete='DELETE')
scan = models.ForeignKey('Scan',on_delete='DELETE')
code
When I list to Show a activities I need to show information about scan and where they come from (source)
like (Activity.Host or Activit.Scan.Source.)
In PHP my Scan table had a "source" flag and an ID field, so I knew in which table to fetch the data from the source.
I know this is not the right way so I want to do this well done using ORM.
if you can help me I will be very grateful.
django model modeling
SOS - HELP :
I am newbie in django ( I came from PHP (Laravel)):
I need modeling the data :
I have same models they are named Sources like(IOT, Sensosr, Totens, app etc..) each source has your particularity(conection params) and similarity, then I have scans, scans use sources information to execute (store information about execution) and produce activities on hosts.
I need to link activities to sources through scans, so that, when a activity is showed, information about hosts, scans, and source are showed.
I learning about abstract but it not so clear !
@dirkgroten thanks for your time, Im Edited it to be more precise
look this models:
code
class Sensor (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
class Crawler (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
code
They are my Sources Models , where data Activities came from...
then
code
class Scan (models.Model):
creation_date = models.DateTimeField(auto_now=True)
# Here I neet to link with a source, but source could be a Crawler, IOT, Sensor or API model
...fields
class Host (models.Model):
creation_date = models.DateTimeField(auto_now=True)
...fields
class Activities (models.Model):
creation_date = models.DateTimeField(auto_now=True)
host = models.ForeignKey('Host',on_delete='DELETE')
scan = models.ForeignKey('Scan',on_delete='DELETE')
code
When I list to Show a activities I need to show information about scan and where they come from (source)
like (Activity.Host or Activit.Scan.Source.)
In PHP my Scan table had a "source" flag and an ID field, so I knew in which table to fetch the data from the source.
I know this is not the right way so I want to do this well done using ORM.
if you can help me I will be very grateful.
django model modeling
django model modeling
edited Nov 20 '18 at 20:53
Adilson Santos da Rocha
asked Nov 20 '18 at 15:17
Adilson Santos da RochaAdilson Santos da Rocha
4413
4413
Please check How to Ask to learn how to formulate your question in an appropriate way for SO. You need to show us what you're trying to do with code, show us your initial models. Please be more specific.
– dirkgroten
Nov 20 '18 at 16:32
btw: google "django relationship through intermediate model" and you'll find plenty of stuff.
– dirkgroten
Nov 20 '18 at 16:33
@dirkgroten thanks for your time:
– Adilson Santos da Rocha
Nov 20 '18 at 20:32
@dirkgroten I reformulate my question ! thanks
– Adilson Santos da Rocha
Nov 20 '18 at 21:06
You need to use generic relations, as documented here. There's a blog post as a good example.
– dirkgroten
Nov 21 '18 at 10:32
|
show 1 more comment
Please check How to Ask to learn how to formulate your question in an appropriate way for SO. You need to show us what you're trying to do with code, show us your initial models. Please be more specific.
– dirkgroten
Nov 20 '18 at 16:32
btw: google "django relationship through intermediate model" and you'll find plenty of stuff.
– dirkgroten
Nov 20 '18 at 16:33
@dirkgroten thanks for your time:
– Adilson Santos da Rocha
Nov 20 '18 at 20:32
@dirkgroten I reformulate my question ! thanks
– Adilson Santos da Rocha
Nov 20 '18 at 21:06
You need to use generic relations, as documented here. There's a blog post as a good example.
– dirkgroten
Nov 21 '18 at 10:32
Please check How to Ask to learn how to formulate your question in an appropriate way for SO. You need to show us what you're trying to do with code, show us your initial models. Please be more specific.
– dirkgroten
Nov 20 '18 at 16:32
Please check How to Ask to learn how to formulate your question in an appropriate way for SO. You need to show us what you're trying to do with code, show us your initial models. Please be more specific.
– dirkgroten
Nov 20 '18 at 16:32
btw: google "django relationship through intermediate model" and you'll find plenty of stuff.
– dirkgroten
Nov 20 '18 at 16:33
btw: google "django relationship through intermediate model" and you'll find plenty of stuff.
– dirkgroten
Nov 20 '18 at 16:33
@dirkgroten thanks for your time:
– Adilson Santos da Rocha
Nov 20 '18 at 20:32
@dirkgroten thanks for your time:
– Adilson Santos da Rocha
Nov 20 '18 at 20:32
@dirkgroten I reformulate my question ! thanks
– Adilson Santos da Rocha
Nov 20 '18 at 21:06
@dirkgroten I reformulate my question ! thanks
– Adilson Santos da Rocha
Nov 20 '18 at 21:06
You need to use generic relations, as documented here. There's a blog post as a good example.
– dirkgroten
Nov 21 '18 at 10:32
You need to use generic relations, as documented here. There's a blog post as a good example.
– dirkgroten
Nov 21 '18 at 10:32
|
show 1 more comment
1 Answer
1
active
oldest
votes
We want to link scan table with different sources like IOT, Crawler, or Sensor or any other Source.
Let me discuss with two approaches for this.
You can have different tables for each one of source and link the scan table through foreign relations among themselves but it will be cumbersome to handle those if dataset becomes large.
Since, these sources have their set of fields predefined and each one of source contain data of specific format. So create a master table having field sourceType i.e iot, sender, crawler or api and extract the required fields from these sources and put in the master source model. and link it with Scan model. You can run some cron job to process these data from different sources redis or kafka can help you in this regard. You can also celery to process these tasks.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396099%2fdjango-modeling-multi-table-reference%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
We want to link scan table with different sources like IOT, Crawler, or Sensor or any other Source.
Let me discuss with two approaches for this.
You can have different tables for each one of source and link the scan table through foreign relations among themselves but it will be cumbersome to handle those if dataset becomes large.
Since, these sources have their set of fields predefined and each one of source contain data of specific format. So create a master table having field sourceType i.e iot, sender, crawler or api and extract the required fields from these sources and put in the master source model. and link it with Scan model. You can run some cron job to process these data from different sources redis or kafka can help you in this regard. You can also celery to process these tasks.
add a comment |
We want to link scan table with different sources like IOT, Crawler, or Sensor or any other Source.
Let me discuss with two approaches for this.
You can have different tables for each one of source and link the scan table through foreign relations among themselves but it will be cumbersome to handle those if dataset becomes large.
Since, these sources have their set of fields predefined and each one of source contain data of specific format. So create a master table having field sourceType i.e iot, sender, crawler or api and extract the required fields from these sources and put in the master source model. and link it with Scan model. You can run some cron job to process these data from different sources redis or kafka can help you in this regard. You can also celery to process these tasks.
add a comment |
We want to link scan table with different sources like IOT, Crawler, or Sensor or any other Source.
Let me discuss with two approaches for this.
You can have different tables for each one of source and link the scan table through foreign relations among themselves but it will be cumbersome to handle those if dataset becomes large.
Since, these sources have their set of fields predefined and each one of source contain data of specific format. So create a master table having field sourceType i.e iot, sender, crawler or api and extract the required fields from these sources and put in the master source model. and link it with Scan model. You can run some cron job to process these data from different sources redis or kafka can help you in this regard. You can also celery to process these tasks.
We want to link scan table with different sources like IOT, Crawler, or Sensor or any other Source.
Let me discuss with two approaches for this.
You can have different tables for each one of source and link the scan table through foreign relations among themselves but it will be cumbersome to handle those if dataset becomes large.
Since, these sources have their set of fields predefined and each one of source contain data of specific format. So create a master table having field sourceType i.e iot, sender, crawler or api and extract the required fields from these sources and put in the master source model. and link it with Scan model. You can run some cron job to process these data from different sources redis or kafka can help you in this regard. You can also celery to process these tasks.
answered Nov 21 '18 at 19:06
Praveen Kumar VermaPraveen Kumar Verma
91
91
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396099%2fdjango-modeling-multi-table-reference%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please check How to Ask to learn how to formulate your question in an appropriate way for SO. You need to show us what you're trying to do with code, show us your initial models. Please be more specific.
– dirkgroten
Nov 20 '18 at 16:32
btw: google "django relationship through intermediate model" and you'll find plenty of stuff.
– dirkgroten
Nov 20 '18 at 16:33
@dirkgroten thanks for your time:
– Adilson Santos da Rocha
Nov 20 '18 at 20:32
@dirkgroten I reformulate my question ! thanks
– Adilson Santos da Rocha
Nov 20 '18 at 21:06
You need to use generic relations, as documented here. There's a blog post as a good example.
– dirkgroten
Nov 21 '18 at 10:32