Answer the question
In order to leave comments, you need to log in
How to do not repeat?
I have two models
file models.py
from django.db import models
# -*- coding: UTF-8 -*-
class LessonOne(models.Model):
russia = models.CharField(max_length=250)
english = models.CharField(max_length=250)
buttons = models.TextField()
def __str__(self):
return self.russia
class LessonTwo(models.Model):
russia = models.CharField(max_length=250)
english = models.CharField(max_length=250)
buttons = models.TextField()
def __str__(self):
return self.russia'
def listdataOne(request):
data = LessonOne.objects.all()
return render(request, 'fighter/listdataOne.html', {'data': data, "amount": len(data)})
def listdataTwo(request):
data = LessonTwo.objects.all()
return render(request, 'fighter/listdataTwo.html', {'data': data, "amount": len(data)})
<li><a href="/fighter/listdataOne">First lesson.</a></li>
<li><a href="/fighter/listdataTwo">Second lesson.</a></li>
Answer the question
In order to leave comments, you need to log in
# -*- coding: UTF-8 -*-
Should be the very first line.
You need one model:
class Lesson(models.Model):
lesson_number = models.IntegerField()
russia = models.CharField(max_length=250)
english = models.CharField(max_length=250)
buttons = models.TextField()
def __str__(self):
return self.russia
def listdata(request, lesson_number):
data = LessonOne.objects.filter(lesson_number=lesson_number )
return render(request, 'fighter/listdataOne.html', {'data': data, "amount": len(data)})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question