I have a use case where in UserProfile model, user details are stored. One of the field is user_company_name.
class UserProfile(BaseModel):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
user_company_name = models.CharField(max_length=254)
Instead of a CharField
I want the field to be a ChoiceField, having drop down of the Company (names) currently present in the database. If the current company of the user is not present in the dropdown I plan to give the user an option to add his or her company to the DB.
Suppose I have a Company model as such:
class Company(BaseModel):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
What should be my Field Choice in the UserProfile model for user_company_name
field.