how to get field value in django admin form save_model
<p>I have the following model:</p>

<pre><code>class Guest(models.Model):
    first_name = models.CharField(max_length=128)
    last_name = models.CharField(max_length=128)
    category = models.ForeignKey(Category)
    player_achievement = models.ForeignKey(PlayerAchievement, related_name="guest_achievements")
    player = models.ForeignKey(Player)
</code></pre>

<p>I want to get the player selected in the form to use in my save_model method:</p>

<pre><code>def save_model(self, request, obj, form, change):
        player = ??? how do i get this from the admin form?


        obj.player = player
        obj.save()
</code></pre>

<p>It depends on how you declared your form. If you inherited the <a href="https://docs.djangoproject.com/en/1.10/topics/forms/modelforms/" rel="nofollow">ModelForm</a>, then you should in most cases use <a href="https://docs.djangoproject.com/en/1.10/ref/forms/fields/#django.forms.ModelChoiceField" rel="nofollow">ModelChoiceField</a> to select the associated <code>Player</code> with your <code>Guest</code> object and this is through calling <code>form.cleaned_data.get('player')</code></p>

python django django-models django-forms django-admin