help please deal with ForeignKey
I have a model:
class UserProfile(models.Model): CHOICES_status = ( ('0', 'статус отключен'), ('1', 'в поиске'), ('2', 'в космосе'), ('3', 'женат'), ('4', 'член партии'), ) user = models.OneToOneField(User) family = models.CharField(max_length=30, blank=True) name = models.CharField(max_length=30, blank=True) nation = models.CharField(max_length=30) status = models.CharField(max_length=30, blank=True, choices=CHOICES_status, default='0') avatar = models.ImageField(upload_to='userprofile/', blank=True) nation_show = models.BooleanField(default=True, blank=True)
she works. the problem is that I would like to keep the list of statuses not in the constant CHOICES_status, but in a separate table
for this, I create and fill in the table, which corresponds to the following model:
class UserStatus(models.Model): status = models.CharField(max_length=30)
but I do not understand how to connect these two models (tables)
if I do this:
class UserProfile(models.Model): user = models.OneToOneField(User) family = models.CharField(max_length=30, blank=True) name = models.CharField(max_length=30, blank=True) nation = models.CharField(max_length=30) status = models.ForeignKey() avatar = models.ImageField(upload_to='userprofile/', blank=True) nation_show = models.BooleanField(default=True, blank=True)
, firstly it does not work, and secondly it is not clear where the instruction to use the drop-down list
please tell me the code example