English 中文(简体)
Django One-To-Many Models
原标题:Django One-To-Many Models

以下模型描述一种脆弱性,以及互联网上指这种脆弱性的URLs。 认为每个欧洲权利论坛都只谈1个弱点,许多欧洲权利论坛将讨论这一脆弱性。 说明这一模式的正确方法吗?

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

  reference_urls = models.ForeignKey(Url, unique=True, blank=True, verbose_name="Reference URLs")
  vendor = models.ForeignKey(Vendor, verbose_name="Vendor")

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

阿伦特人的申请为参考文献提供了一个选箱,该箱是我想要的。 当我增加一个新的脆弱目标时,所有已进入的URLs在这种下降中表现出来,这再次是非自然的。 我认为,这应该与博客的评论,即这样的话非常相似。 该评论适用于单一博客条目,没有其他条目,一个博客条目可能有许多评论。 我如何在Django模式中表明这一点?

最佳回答

更应该如此:

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)

如果你再谈一下每一次乌拉尔会谈,具体的脆弱性,那么在达詹戈·达克问题上,你的关系是:

至于供应商领域,你只是增加另一个类别,如Vuln。 例如:

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

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签