0

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.

1 Answers1

0

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.

  1. 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.

  2. 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.