Reputation: 11
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.
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
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? is there any working example?
Upvotes: 0
Views: 148
Reputation: 239290
Try:
Users.objects.exclude(cUsers__name='Some Country')
See: https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships
Upvotes: 3