Issue
i have two apps in 1)boq 2)inputs inputs has a model building
class building(models.Model):
building = models.CharField(max_length=300
my boq app has a model boqmodel
class boqmodel(models.Model):
code = models.IntegerField()
building =models.CharField(max_length=300)
level = models.CharField(max_length=300)
activity = models.CharField(max_length=300)
subactivity = models.CharField(max_length=300)
duration=models.IntegerField()
linkactivity= models.CharField(max_length=300)
linktype= models.CharField(max_length=300)
linkduration=models.IntegerField()
plannedstart=models.DateField()
plannedfinish=models.DateField()
actualstart=models.DateField()
actualfinish=models.DateField()
i have a form in boq app as follows
class boqform(forms.ModelForm):
class Meta:
model = boqmodel
fields = ['code',
'building',
'level',
'activity',
'subactivity',
'duration',
'linkactivity',
'linktype',
'linkduration',
'plannedstart',
'plannedfinish',
'actualstart',
'actualfinish']
Building column is same in boq and inputs app.
I need to have a drop down in boq form for building with values from model in inputs.building model
Solution
class building(models.Model):
building = models.CharField(max_length=300)
def __str__(self):
return self.building
class boqmodel(models.Model):
code = models.IntegerField()
#building =models.CharField(max_length=300)
building = models.ForeignKey(building, on_delete=models.SET_NULL, null=True)
level = models.CharField(max_length=300)
activity = models.CharField(max_length=300)
subactivity = models.CharField(max_length=300)
duration = models.IntegerField()
linkactivity = models.CharField(max_length=300)
linktype = models.CharField(max_length=300)
linkduration = models.IntegerField()
plannedstart = models.DateField()
plannedfinish = models.DateField()
actualstart = models.DateField()
actualfinish = models.DateField()
Done
Answered By - Raviteja Reddy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.