Answer the question
In order to leave comments, you need to log in
How to display the data of two models in django?
Good day! Such a problem: there are models in different applications
In the adminpanel:
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(verbose_name='Ник', max_length=255, blank = True, null = True)
email = models.EmailField(
verbose_name='E-mail',
max_length=255,
unique=True,
db_index=True)
userPhoto = models.ImageField(verbose_name = 'Фотография', upload_to='userPhotos/%Y/%m/%d', blank = True, null = True)
name = models.CharField(verbose_name = 'Имя', max_length = 20, blank = True)
patronymic = models.CharField(verbose_name = 'Отчество', max_length = 30, blank = True, null = True)
surname = models.CharField(verbose_name = 'Фамилия', max_length = 30, blank = True)
birthdate = models.DateField(verbose_name = 'Дата рождения', blank = True, null = True)
address = models.ForeignKey(Addresses)
passportSeries = models.CharField(verbose_name = 'Серия паспорта', max_length = 10, blank = True)
passportNumber = models.IntegerField(verbose_name = 'Номер паспорта', default = 0)
telephoneNumber = models.CharField(verbose_name = 'Номер телефона', max_length = 20, blank = True)
is_active = models.BooleanField(verbose_name = 'Активен?', default = True)
is_admin = models.BooleanField(verbose_name = 'Администратор?', default = False)
objects = UserManager()
USERNAME_FIELD = 'email'
def get_full_name(self):
return '%s %s %s' % (self.name, self.patronymic, self.surname,)
def get_short_name(self):
return self.username
def __unicode__(self):
return self.email
def has_perm(self, perm, obj=None):
return True
def has_module_perms(self, app_label):
return True
@property
def is_staff(self):
return self.is_admin
class Student(User):
institute = models.ForeignKey(Institutes)
chair = models.ForeignKey(Chairs)
academicGroupPrefix = models.CharField(verbose_name = 'Префикс группы', max_length = 10, blank = True, null = True)
academicGroupNumber = models.IntegerField(verbose_name = 'Номер группы', blank = True, null = True)
gradebookNumber = models.IntegerField(verbose_name = 'Номер зачётки', blank = True, null = True)
parents = models.CharField(verbose_name = 'Родители', max_length = 20, blank = True, null = True)
accessionYear = models.IntegerField(verbose_name = 'Год поступления', blank = True, null = True)
endYear = models.IntegerField(verbose_name = 'Год окончания', blank = True, null = True)
class RatingActive(models.Model):
student = models.ForeignKey(Student, on_delete = models.CASCADE)
subject = models.ForeignKey(Subjects, on_delete = models.CASCADE, null = True)
ratingFiveMark = models.IntegerField()
ratingNationalMark = models.CharField(max_length = 19)
ratingECTS = models.IntegerField()
hoursOfAbsences = models.CharField(max_length = 5)
def __str__(self):
return self.student.name
Answer the question
In order to leave comments, you need to log in
https://docs.djangoproject.com/en/1.8/ref/request-...
Something seems to me not to be inherited from the user here,
but
def view_foo(request):
return render(request, 'foo.html', {
'student': Student.objects.get(pk=request.user.pk),
'rates': RatingActive.objects.filter(pk=request.user.pk)
})
<h1>{{ student.get_full_name() }}
<ul>
{% for r in rates %}
<li>{{ r.subject }} - {{ r.rating_five_mark }}
{% endfor %}
def __str__(self):
def __unicode__(self):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question