操作系统-Windows10
Python-3.7.4
姜戈 - 2.1
我想展示这个模型。像这样在此输入图像描述 https://i.stack.imgur.com/2UERg.jpg
但我不知道。我怎样才能做到这一点。我尝试了三个月来解决这个问题:(
我已经有了 MySQL 数据库。所以,我必须保留这些数据结构(模型)
管理员继承?
覆盖 Django Admin 中的查询集?
我不知道该怎么做。我不懂Queryset,stORM...
因为我刚刚开始使用Django 3个月。
我必须解决这个问题。一个视图(模板)中的多个模型(表==类)
但我不能..请告诉我提示,解决方案,任何东西
模型.py
from django.conf import settings
from django.db import models
from django.utils import timezone
class Exam(models.Model):
idexam = models.IntegerField(primary_key=True)
trueanswernum = models.IntegerField(db_column='trueAnswerNum', blank=True, null=True) # Field name made lowercase.
falseanswernum = models.IntegerField(db_column='falseAnswerNum', blank=True, null=True) # Field name made lowercase.
exammain = models.TextField(db_column='examMain', blank=True, null=True) # Field name made lowercase.
questionsubmain = models.TextField(db_column='questionSubMain', blank=True, null=True) # Field name made lowercase.
answerno1 = models.TextField(db_column='answerNo1', blank=True, null=True) # Field name made lowercase.
answerno2 = models.TextField(db_column='answerNo2', blank=True, null=True) # Field name made lowercase.
answerno3 = models.TextField(db_column='answerNo3', blank=True, null=True) # Field name made lowercase.
answerno4 = models.TextField(db_column='answerNo4', blank=True, null=True) # Field name made lowercase.
rightanswer = models.IntegerField(db_column='rightAnswer', blank=True, null=True) # Field name made lowercase.
originalremark = models.TextField(db_column='originalRemark', blank=True, null=True) # Field name made lowercase.
writer = models.CharField(max_length=45, blank=True, null=True)
writingdate = models.DateTimeField(db_column='writingDate', blank=True, null=True, auto_now_add=True) # Field name made lowercase.
sources = models.CharField(max_length=45, blank=True, null=True)
class Meta:
managed = False
db_table = 'boards_exam'
def __str__(self):
return self.exammain
class Examhistory(Exam):
idexamhistory = models.AutoField(db_column='idExamhistory', primary_key=True) # Field name made lowercase.
idexam = models.IntegerField()
examyear = models.IntegerField(db_column='examYear') # Field name made lowercase.
examtypecode = models.IntegerField(db_column='examTypeCode') # Field name made lowercase.
yearexamnum = models.IntegerField(db_column='yearExamNum', blank=True, null=True) # Field name made lowercase.
examsubj = models.IntegerField(db_column='examSubj', blank=True, null=True) # Field name made lowercase.
examnum = models.IntegerField(db_column='examNum', blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'boards_examhistory'
unique_together = (('idexamhistory', 'idexam'),)
class Examtype(models.Model):
examtypecode = models.IntegerField(db_column='examTypeCode', primary_key=True) # Field name made lowercase.
examtypename = models.CharField(db_column='examTypeName', max_length=20, blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'boards_examtype'
class Lawinfo(models.Model):
lawnamecode = models.IntegerField(db_column='lawNameCode', primary_key=True) # Field name made lowercase.
lawname = models.CharField(db_column='lawName', max_length=25, blank=True, null=True) # Field name made lowercase.
lawadmin = models.CharField(db_column='lawAdmin', max_length=15, blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'boards_lawinfo'
class Lawtext(models.Model):
idlawtext = models.AutoField(primary_key=True)
lawnamecode = models.IntegerField(db_column='lawNameCode', blank=True, null=True) # Field name made lowercase.
lawcategory = models.IntegerField(db_column='lawCategory', blank=True, null=True) # Field name made lowercase.
lawcontent_jo = models.CharField(db_column='lawContent_jo', max_length=5, blank=True, null=True) # Field name made lowercase.
lawcontent_hang = models.CharField(db_column='lawContent_hang', max_length=5, blank=True, null=True) # Field name made lowercase.
lawcontent_ho = models.CharField(db_column='lawContent_ho', max_length=5, blank=True, null=True) # Field name made lowercase.
lawcontent_mok = models.CharField(db_column='lawContent_mok', max_length=5, blank=True, null=True) # Field name made lowercase.
lawtext = models.TextField(db_column='lawText', blank=True, null=True) # Field name made lowercase.
update_date = models.DateTimeField(blank=True, null=True)
class Meta:
managed = False
db_table = 'boards_lawtext'
class Relatedlaw(models.Model):
idrelatedlaw = models.AutoField(primary_key=True)
idexam = models.IntegerField()
lawnamecode = models.IntegerField(db_column='lawNameCode', blank=True, null=True) # Field name made lowercase.
lawcategory = models.CharField(db_column='lawCategory', max_length=5, blank=True, null=True) # Field name made lowercase.
lawcontent_jo = models.CharField(db_column='lawContent_jo', max_length=5, blank=True, null=True) # Field name made lowercase.
lawcontent_hang = models.CharField(db_column='lawContent_hang', max_length=5, blank=True, null=True) # Field name made lowercase.
lawcontent_ho = models.CharField(db_column='lawContent_ho', max_length=5, blank=True, null=True) # Field name made lowercase.
lawcontent_mok = models.CharField(db_column='lawContent_mok', max_length=5, blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'boards_relatedlaw'
unique_together = (('idrelatedlaw', 'idexam'),)
# Create your models here.
Views.py
from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from .models import Exam
def exam_list(request):
exams = Exam.objects.filter(writingdate__lte=timezone.now()).order_by('writingdate')
return render(request, 'boards/exam_list.html', {'exams': exams})
def exam_detail(request, pk):
exam = get_object_or_404(Exam, pk=pk)
return render(request, 'boards/exam_detail.html', {'exam': exam})
# Create your views here.
admin.py
from django.contrib import admin
from .models import Exam
admin.site.register(Exam)
# Register your models here.