In my django application I have three models, People, Reviews and File.
class People(models.Model):
firstname = models.charField(max_length=20)
lastname = models.charField(max_length=20)
class Reviews(models.Model):
STATUSES = (
('pending', 'Pending'),
('approved', 'Approved'),
('rejected', 'Rejected')
)
person = models.OneToOneField(People, on_delete=models.CASCADE, primary_key=True)
status = models.CharField(max_length=10, choices=STATUSES, default='pending')
comment = models.TextField()
class File(models.Model):
owner = models.OneToOneField(Reviews, on_delete=models.CASCADE, primary_key=True)
comment = models.TextField()
issue_date = models.DateField(auto_now_add=True)
See that OneToOneField
on the File model? I need to be able to filter that dropdown, based on two conditions.
- It needs to only display records from the
Reviews
model that have a status of approved.Reviews.objects.filter(status="approved")
- The displayed results must not already exist in the
File
model's records.File.objects.all()
And also, while creating an instance of the File model, when a value is selected from the dropdown, how could I automatically populate the comment field
with the value from the Review model's comment field?
I can't quite figure it out.