I'm working on a web project, and I'm still really new to Django and the idea behind models. Basically, I want to create accounts that allow each user to save a group of locations. Currently, I've created models for each location (which must be unique to the user) and each user:
class Location(models.Model):
name = models.CharField(max_length=70)
longitude = models.DecimalField(max_digits=7,decimal_places=4)
latitude = models.DecimalField(max_digits=7,decimal_places=4)
custDescription = models.CharField(max_length=500)
custName = models.CharField(max_length=70)
def __unicode__(self):
return self.name
(...)
class User(models.Model):
username = models.CharField(max_length=32)
password = models.CharField(max_length=32)
locations = []
(...)
def addLocation(self, Location):
if (Location not in locations):
self.locations += Location
else:
return None
def removeLocation(self, Location):
if (Location in locations):
i = locations.index(Location)
locations.remove(i)
else:
return None
Will django's models support the list that I use in User.locations and allow me to add or remove a Location to it? If not, advice on more effective methods would be greatly appreciated!