[英]Django Howto Filter out the users that belongs to a particular country and not all users
Apologize if the code below is not up to a decent programer, as i am not related to computers at all, but i would like to automate a tedious process and i find Django just interesting.. and for the life of me i can not just simply find the answer. 抱歉,下面的代码不是由一个像样的程序员决定的,因为我根本与计算机无关,但是我想使一个乏味的过程自动化,我发现Django只是一个有趣的事情..对于我的生活,我不能仅仅只需找到答案。
Having the following models.py i would like to filter out the users that belongs to a particular country and not all users, and save this information on a sqlite3 db 具有以下models.py,我想过滤出属于特定国家/地区的用户,而不是所有用户,并将此信息保存在sqlite3数据库中
class Country(models.Model):
name = models.CharField(max_length=50)
def __unicode__(self):
return self.name
class Meta:
verbose_name = 'Countries Uploaded'
class Users(models.Model):
name = models.CharField(max_length=50)
cUsers = models.ForeignKey(Country)
def __unicode__(self):
return self.name
class Meta:
verbose_name = 'Users on a country'
class GoalsinCountry(models.Model):
Country = models.ForeignKey(VideoTopic)
'HERE I WOULD LIKE TO SEE THE USERS IN EACH COUNTRY'
name = models.CharField(max_length=50)
descr = models.TextField(blank=True, null=True)
def __unicode__(self):
return self.name
class Meta:
verbose_name = 'Goals Topic'
Would this be possible to do with Django? 使用Django可能吗? is there any working example?
有什么可行的例子吗?
Try: 尝试:
Users.objects.exclude(cUsers__name='Some Country')
See: https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships 参见: https : //docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.