I am getting an error about a reverse accessor clash with the following model in django (Linux Mint - Python 2.7.6 - django.VERSION (1, 11, 0, u'final', 1)):
class Equipment(models.Model):
YES_NO = (
('Y', 'Yes'),
('N', 'No'),
)
Serial = models.CharField(max_length = 50)
Name = models.CharField(max_length = 200)
# This can probably be dropped based on max length of IPv6 address
ManagementIP = models.CharField(max_length = 100)
is_active = models.CharField(max_length = 1, choices = YES_NO)
EquipModel = models.ForeignKey(EquipmentModel)
# I don't understand why a related name is required here.
location = models.ForeignKey(Location,
#related_name='equipment_location_related'
)
Giving me the following error:
ERRORS:
KMZ.Equipment.location: (fields.E304) Reverse accessor for 'Equipment.location' clashes with reverse accessor for 'Equipment.Location'.
HINT: Add or change a related_name argument to the definition for 'Equipment.location' or 'Equipment.Location'.
netmgr.Equipment.Location: (fields.E304) Reverse accessor for 'Equipment.Location' clashes with reverse accessor for 'Equipment.location'.
HINT: Add or change a related_name argument to the definition for 'Equipment.Location' or 'Equipment.location'.
Looking online this is common if accessing the same model multiple times from a single model, I am not doing that here. The error goes away if I uncomment the related_name line but what I'm not understanding where the other reference is coming from (location was originally Location which made the error more confusing).
Is there any way to see what is creating Equipment.Location accessor? I am now adding this field and it hasn't even been migrated into the database yet so I can safely remove the field temporarily.
Here is the definition of Location and EquipmentModel:
class Location(models.Model):
'''
Describes individual sites (usually towers).
'''
TOWER_STATES = (
('A', 'Site Acquired'),
('P', 'Site Provisioning in Progress'),
('L', 'Live / In Production'),
('T', 'Tear Down'),
('D', 'Decommisioned'),
)
Network = models.ForeignKey(Network)
Name = models.CharField(max_length = 200, unique = True) # Short hand name of site (3-letter code)
Description = models.CharField(max_length = 200) # Full name of site
zabbixGroup = models.CharField(max_length = 200) # Group name in zabbix
latitude = models.DecimalField(max_digits = 13, decimal_places = 10, blank = True, null = True)
longitude = models.DecimalField(max_digits = 13, decimal_places = 10, blank = True, null = True)
elevation = models.DecimalField(max_digits = 6, decimal_places = 3, blank = True, null = True)
state = models.CharField(max_length = 1, choices = TOWER_STATES)
generalNotes = models.TextField(blank = True) # Anything about the site that doesn't fit in the other note fields.
accessNotes = models.TextField(blank = True) # Any notes about accessing site (is a police escort required?)
streetAddress = models.TextField(blank = True) # Street address of tower (if applicable).
def __str__(self):
return self.Description
class Meta:
ordering = ["Description"]
class EquipmentModel(models.Model):
'''
Describes the different types of equipment used.
'''
EQUIPMENT_TYPES = (
('AM', 'Antenna (Multipoint)'),
('AP', 'Antenna (Point-to-Point)'),
('BB', 'Backup Power Battery'),
('BC', 'Backup Power Controller'),
('PI', 'Power Injector'),
('RA', 'RF Unit (Access Point)'),
('RB', 'RF Unit (Backhaul)'),
('RS', 'Router / Switch'),
('UN', 'Unknown'),
)
Name = models.CharField(max_length = 200) # Model number
Description = models.CharField(max_length = 200)
manufacturer = models.ForeignKey(EquipmentManufacturer)
equipmentClass = models.CharField(max_length = 10, choices = EQUIPMENT_TYPES, default = 'U')
# Tech details can maybe be stored in a 'JSONField'?
# First need to decide what we will even use this for before making that decision.
modelData = models.TextField(blank = True)
def __str__(self):
return self.Name
class Meta:
ordering = ["Name"]