mardi 14 juillet 2015

I have a choice field on a model.py which allows the user to select a field value another model from within my sqlite database

I have a choice field on a model.py which allows the user to select a field value from another model from within my sqlite database. Using the development server ("python manage.py runserver" command choice field is populated correctly) this is populated during the runserver command. The problem I have is I would like the choice field to update automaticaly when we add a new feild.

model 1: 
class UserData(models.Model):
usertype = models.IntegerField('User Type',choices=((0, ("Boat Owner")),(1, ("Boat Manager")),(2, ("Travel Agent"))))

model 2:
class Boat_Detail(models.Model):
BOAT_MANAGER_LIST = list ( (obj.name,obj.name) for obj in UserData.objects.filter(usertype=1) )
boat_manager    = models.CharField(max_length=200, choices=BOAT_MANAGER_LIST,verbose_name="Boat Manager")

Aucun commentaire:

Enregistrer un commentaire