Форум сайта python.su
Есть модели:
class Country(models.Model): name = models.CharField(_("Name"), max_length=50, unique=True) class Profile(models.Model): name = models.CharField(_("Name"), max_length=50, unique=True) country = models.ForeignKey(Country)
Офлайн
То, что придумалось сходу на коленке:
from random import choice countries = Country.objects.all() diff_countr = [] while 1: c = choice(countries) if c not in diff_countr: diff_countr.append(c) if len(diff_countr) > 2: break profiles = Profile.objects.filter(country__in = diff_countr)
Офлайн
Вот тут посмотрите:
http://stackoverflow.com/questions/3852104/select-distinct-individual-columns-in-django
Отредактировано Saturn (Авг. 11, 2012 21:13:49)
Офлайн