Django passing foreign key to form
<p>I'm new to django.</p>

<p>I need to take the id from the request and when the form is created I want it to make the value of complaintid field from this value and rest from form itself.</p>

<p>models.py</p>

<pre><code>class Complaint(models.Model):
    complaintid= models.AutoField(primary_key=True)
    dateofcomplaint=models.DateTimeField(auto_now=False, auto_now_add=True)
    content = models.TextField()
    policestation= models.CharField(max_length=120)
    location=models.TextField()

    def __unicode__(self):
        return unicode(self.complaintid)
    def __str__(self):
        return self.complaintid
    def get_absolute_url(self):
        return reverse("crimefiles:detail", kwargs={"id":self.complaintid}) 

class Fir(models.Model):
    firid=models.CharField(max_length=10,primary_key=True)
    complaintid=models.ForeignKey(Complaint,default=None)
    signedby= models.CharField(max_length=20)
    content=models.TextField(default="First Information Report")

    def  __unicode__(self):
        return self.firid

    def __str__(self):
        return self.firid
</code></pre>

<p>views.py</p>

<pre><code>def fir_create(request,id=None):
    form =FirForm(request.POST or None)
    if form.is_valid():
        instance=form.save(commit=False)
        instance.save()
        messages.success(request,"sucessfully Created")
        return HttpResponseRedirect()
    context={
    "form":form
    }
    return render(request,"fir_form.html",context)
</code></pre>

<p>forms.py</p>

<pre><code>class FirForm(forms.ModelForm):
    class Meta:
        model=Fir
        fields=[
        "firid",
        "signedby",
        "content"]
</code></pre>