Asking for your support again, I am making an application to inventory the electrical and optical ports of various equipment, and it is not clear to me how to relate a model with several models.
I have the following two objects:
class ITarjeta(models.Model):
tipo_tarjeta = models.ForeignKey('catalogo.Tarjeta')
nomenclatura = models.CharField(max_length=30)
etiqueta = models.CharField(max_length=30)
equipo = models.ForeignKey(IEquipo)
autor = models.ForeignKey(settings.AUTH_USER_MODEL)
fecha_hora_alta = models.DateTimeField(
null=True, blank=True, default=timezone.now)
class Meta:
verbose_name_plural = "Tarjetas"
def __str__(self):
return str(self.nomenclatura)
class ISwitch(models.Model):
tipo_switch = models.ForeignKey('catalogo.Switch')
nomenclatura = models.CharField(max_length=30)
etiqueta = models.CharField(max_length=30)
rack = models.ForeignKey(IRack)
autor = models.ForeignKey(settings.AUTH_USER_MODEL)
fecha_hora_alta = models.DateTimeField(
null=True, blank=True, default=timezone.now)
class Meta:
verbose_name_plural = "Switc's"
def __str__(self):
return str(self.nomenclatura)
And also created two other objects that are what I want to relate:
class IPuertoOptico(models.Model):
nomenclatura = models.CharField(max_length=30)
equipo = models.ForeignKey(ITarjeta) //tambien lo quiero relacionar con ISwtch
autor = models.ForeignKey(settings.AUTH_USER_MODEL)
fecha_hora_alta = models.DateTimeField(
null=True, blank=True, default=timezone.now)
class Meta:
verbose_name_plural = "Puertos Opticos en Equipos"
def __str__(self):
return '%s' % (self.nomenclatura)
class IPuertoElectrico(models.Model):
nomenclatura = models.CharField(max_length=30)
equipo = models.ForeignKey(ITarjeta) //tambien lo quiero relacionar con ISwtch
autor = models.ForeignKey(settings.AUTH_USER_MODEL)
fecha_hora_alta = models.DateTimeField(
null=True, blank=True, default=timezone.now)
class Meta:
verbose_name_plural = "Puertos Electricos en Equipos"
def __str__(self):
return '%s' % (self.nomenclatura)
I decided to relate the ports with the equipment since the equipment can have many ports, but a port can only have one computer. The problem comes when I want to relate the 'IPuertoElectrico' model to the 'ISwitch' and 'ITarjeta' models.
Someone can guide me on what is the best way to make these relationships.
Greetings.