我正在尝试开发一个计分板网站,该网站将反映用户及其各自的分数,但是由于我对django框架和python并不熟悉,因此我面临着很多开发方面的问题。
>在我遇到错误的记分牌代码下面。如果有人遇到或开发了记分牌,请帮助我解决代码。 谢谢!
models.py
var input = new HashSet<int>(); // accepts only unique values
while (input.Count() < 5)
{
Console.WriteLine("enter value");
int temp; // In newer C# it can be moved to TryParse e.g "out int temp"
if (Int32.TryParse(Console.ReadLine(), out temp))
{
if (input.Contains(temp))
{
Console.WriteLine("this number is already in collection");
}
else
{
input.Add(temp);
}
}
else
{
Console.WriteLine("incorrect value");
}
}
// order by(lambda_expression) allows you to specify by "what things"
// you'd want to order that collection. In this case you're just sorting
// by numbers, but if it was complex objects collection then you'd be
// able to sort by e.g student => student.Money; which would mean that
// you're sorting students by their Money count.
foreach (var number in input.OrderBy(x => x))
{
Console.WriteLine(number);
}
答案 0 :(得分:-1)
您犯了两个错误,一个是在模型 priority 中添加了所有与外键相关的名称,并注释了member1_choice和Consult_choice代码,请运行 python manage.py makemigrations 命令之后,您将注释掉该代码,因为它已创建了依赖项。
我修改了您的代码,请看看。
class member1(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name + ',' + self.contact_number + ',' + self.yourpost + " , " + str(self.department).upper()
class Score(models.Model):
granted_by = models.ForeignKey(member1, default=0)
granted_to = models.ForeignKey(member1, default=0, related_name="granted_to")
class priority(models.Model):
link = models.ForeignKey(member1, on_delete=models.CASCADE, related_name='priority_link')
score = models.ForeignKey(member1, on_delete=models.CASCADE, related_name='priority_score')
name = models.ForeignKey(member1, on_delete=models.CASCADE, related_name='priority_name')
def __str__(self):
return str(self.link) + ',' + str(self.number)
def alpha_name(self):
return str(self.link.name)
def score(self):
return str(score)
member1_choice = [
i.tuple() for i in member1.objects.all()
]
consult_choice = [
i.tuple() for i in consultant.objects.all()
]