python - Saving lists in django models -
i'm working on web project, , i'm still new django , thought behind models. basically, want create accounts allow each user save grouping of locations. currently, i've created models each location (which must unique user) , 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): homecoming 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: homecoming none def removelocation(self, location): if (location in locations): = locations.index(location) locations.remove(i) else: homecoming none will django's models back upwards list utilize in user.locations , allow me add together or remove location it? if not, advice on more effective methods appreciated!
maybe should take django docs
you have that
class user(models.model): #your implementation of user class location(models.model): #.... user = models.foreignkey(location) it possible access locations this:
u = <some_query_for_a_user> locations = u.location_set python django django-models database-table
No comments:
Post a Comment