How do I get the value of a selected model choice field? I have a model that has a field 'user' as a foreignKey and I am trying to figure out how to get the value of a user that was selected.
I have a form that looks like below,
class update_entitlement_form(forms.ModelForm):
class Meta:
model = month_and_year
fields = ['user', 'Month', 'Year']
class month_and_year(models.Model):
user = models.ForeignKey(User, default='', on_delete=models.CASCADE)
Month = models.CharField(max_length=100, default="", null=True)
Year = models.CharField(max_length=100, default='')
def __str__(self):
return self.user.first_name
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y6qcXvcxEqfapFF2NLBJ7r5bEwKCzL3Nj%2B5SmTTBWsaKg%40mail.gmail.com.
No comments:
Post a Comment