mardi 8 décembre 2015

Django Model: Multiple foreign keys or one to one field

i'm having problems with the concept of relationship in django models.

Let's see my example:

I have this table/class into models.py:

class PacketEventsInformation(models.Model):

ID_IP_Source = models.<Relationship>(Ips, on_delete=models.CASCADE)
ID_IP_Dest = models.<Relationship>(Ips, on_delete=models.CASCADE)
ID_Source_Port = models.<Relationship>(Ports, on_delete=models.CASCADE)
ID_Dest_Port = models.<Relationship>(Ports, on_delete=models.CASCADE)
Protocol = models.CharField(max_length=20)
ID_Source_MAC = models.<Relationship>(Macs, on_delete=models.CASCADE)
ID_Dest_MAC = models.<Relationship>(Macs, on_delete=models.CASCADE)
RAW_Info = models.TextField()
TAG = models.ForeignKey(Tags, on_delete=models.CASCADE)

def __str__(self):
    return '%s' % self.id

At this point, I defined the relationship between all my ID fields and ID fields of another tables/classes (Pkey) like ForeignKey.

Well, If I execute migrate into my terminal, I get this:

./manage.py migrate 
app.PacketEventsInformation.ID_Dest_MAC: (fields.E304) Reverse accessor for 'PacketEventsInformation.ID_Dest_MAC' clashes with reverse accessor for 'PacketEventsInformation.ID_Source_MAC'.
......

I understand the definition of ManyToMany, OneToOne and OnetoMany (Foreign Key), but I have no idea why can't do it this. Maybe the answer could be create intermediate tables with that Fkeys or put OneToOne relation between that ids....

Thanks for your answers =)

PD:

ID_IP_Source/Dest can be the same

ID_Source/Dest_Port can be the same

ID_Source/Dest_MAC can be the same

Aucun commentaire:

Enregistrer un commentaire