hi,
i am new in django, i have a problem with instance when pass it in form. Because my instance has 10 field including 3 foreign key field.
when i pass instance to the form in views, i only see that the foreign key field attribute only retrive their id only but i want to retrive other field from foreign key table.
If it possible please help me.
this is the model which i use as instance to pass through form
![[Image: open?id=0B4m-tBXP7BN0Z0tMWkJNN3JqNzQ]](https://drive.google.com/open?id=0B4m-tBXP7BN0Z0tMWkJNN3JqNzQ)
image link:
https://drive.google.com/open?id=0B4m-tB...kJNN3JqNzQ
in this image 1st 2 field are shown just foreign key. But i want here to retrive other value from foreign key table
please help, if you know how to do it.
thanks in advance
i am new in django, i have a problem with instance when pass it in form. Because my instance has 10 field including 3 foreign key field.
when i pass instance to the form in views, i only see that the foreign key field attribute only retrive their id only but i want to retrive other field from foreign key table.
If it possible please help me.
this is the model which i use as instance to pass through form
class CreateMasterBet(models.Model): owner = models.ForeignKey(User, null=True, related_name='owner') opposite = models.ForeignKey(User, null=True, related_name='opposite') ownerTeam = models.CharField(max_length=100, default='') oppositeTeam = models.CharField(max_length=100, default='') match = models.ForeignKey(Match) ownerProposedRate = models.IntegerField() ownerProposedRateForOpposite = models.IntegerField() betis = models.CharField(max_length=20, default='open') howMany = models.IntegerField(default=1) time = models.DateTimeField(default=now) def __str__(self): return str(self.owner) + "( " + str(self.ownerTeam) + " )"the forms for this model instance is below:
class BetEditForm(forms.ModelForm): owner = forms.CharField(max_length=100, required=False, widget=forms.TextInput(attrs={'placeholder': 'Owner', 'class': 'form-control'})) opposite = forms.CharField(max_length=100, required=False, widget=forms.TextInput(attrs={'placeholder': 'Opposite', 'class': 'form-control'})) ownerTeam = forms.CharField(max_length=100, required=False, widget=forms.TextInput(attrs={'placeholder': 'Owner Team', 'class': 'form-control'})) oppositeTeam = forms.CharField(max_length=100, required=False, widget=forms.TextInput(attrs={'placeholder': 'Opposite Team', 'class': 'form-control'})) match = forms.CharField(max_length=100, required=False, widget=forms.TextInput(attrs={'placeholder': 'Match', 'class': 'form-control'})) ownerProposedRate = forms.IntegerField(required=False, widget=forms.TextInput(attrs={'placeholder': 'Owner need to pay', 'class': 'form-control'})) ownerProposedRateForOpposite = forms.IntegerField(required=False, widget=forms.TextInput(attrs={'placeholder': 'Opposite team pay me', 'class': 'form-control'})) betis = forms.CharField(max_length=20, required=False, widget=forms.TextInput(attrs={'placeholder': 'Bet Status', 'class': 'form-control'})) howMany = forms.IntegerField(required=False, widget=forms.TextInput(attrs={'placeholder': 'Number of Bets', 'class': 'form-control'})) time = forms.DateTimeField(required=False, widget=forms.TextInput(attrs={'placeholder': 'Match Played At', 'class': 'form-control'})) class Meta: model = CreateMasterBet fields = ('owner', 'opposite', 'ownerTeam', 'oppositeTeam', 'match', 'ownerProposedRate', 'ownerProposedRateForOpposite', 'betis', 'howMany', 'time')in views.py i pass the model instance in the form
instance = CreateMasterBet.objects.get(id=betid) form = BetEditForm(request.POST or None, instance=instance)then in template i only see the corresponding foreign key fields only retrive id , but in this place i want to retrive other information from foreign key table
image link:
https://drive.google.com/open?id=0B4m-tB...kJNN3JqNzQ
in this image 1st 2 field are shown just foreign key. But i want here to retrive other value from foreign key table
please help, if you know how to do it.
thanks in advance