[Solved]-Django One-To-Many Models

23πŸ‘

βœ…

It should be more like this:

class Vuln(models.Model): 
  pub_date = models.DateTimeField("Publication Date") 
  short_description = models.CharField("Description", max_length=70)
  vendor = models.ForeignKey(Vendor, verbose_name="Vendor") 

class Url(models.Model): 
  url = models.URLField("URL", max_length=200)
  vulnerability = models.ForeignKey(Vuln)

If you’re saying each Url talks about a specific vulnerability, then there is your relation in the Django DBM πŸ™‚

As for the vendor field, you simply add another class, much like Class Vuln. For example:

class Vendor(models.Model): 
  field_names_go_here = models.TextField(max_length=70)
  short_description = models.CharField("Description", max_length=70)

Hope this helps!
Regards, Alex

πŸ‘€Alex

Leave a comment