'Return multiple fields from django model
As the title says, I want to return two fields (semester, subject) separately from semSubject model and access them in Sem1Attendance.
Code as follows,
models.py
class semSubject(models.Model):
name = models.CharField(max_length=100)
code = models.CharField(max_length=7, primary_key=True)
category = models.CharField(max_length=9,default="Theory")
sem = models.IntegerField(null=True)
def __str__(self):
return self.name
class Sem1Attendance(models.Model):
reg_no = models.ForeignKey(Sem1Students, on_delete=models.CASCADE)
status = models.CharField(max_length=10, choices=STATUS)
semester = models.ForeignKey(semSubject,related_name='sem_name', on_delete=models.CASCADE, default=1)
subject = models.ForeignKey(semSubject, related_name='sub_name', on_delete=models.CASCADE)
date = models.DateField(auto_now_add=True)
EDIT: This is how it appears in the admin panel, https://shorturl.at/dFZ58, I want it to display semester and subjects separately.
Is there a way to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
