我不确定我是否正确地提出了这个问题,但这是我想做的。
在 django admin 中,我想编写一个操作,对我的参赛者列表进行随机排序,并且不允许两个名字相同的人在彼此的 4 条记录内。所以基本上,如果你有 John L. John C. Carey J, Tracy M. Mary T.,记录会像这样列出:
约翰·L。
玛丽·T。
凯里·J。
特蕾西·T。
约翰 C。
OR
我如何编写一个动作来创建随机组,其中两个同名的人不会在同一个组中,如下所示:
John L. John C. Carey J, Tracy M. Mary T. =
第 1 组
约翰·L。
玛丽·T。
凯里·J。
特蕾西·T。
第 2 组
约翰 C。
如果不是很清楚,请原谅我,让我知道,我会尝试进一步指定,但任何帮助将不胜感激
EDIT:
Is this what you are referring to? I can't quite figure out how to compare the fields to see if they are the same
Model:
class people(models.Model)
fname = model.CharField()
lname = model.CharField()
group = model.IntegerField()
View:
N = 4
Num = randint(0, N-1)
for x in queryset:
x.group = Num
if group == group| fname == fname | lname == lname:
x.group = (Num + 1) % N