from django.db import models

class Country(models.Model):
    name = models.TextField()
    iso_code = models.CharField(max_length=2, unique=True)

    def __unicode__(self):
        return self.name

class Artist(models.Model):
    name = models.TextField()
    mbid = models.TextField(unique=True)
    country = models.ForeignKey(Country)

from django.db import models

class Country(models.Model):
    name = models.TextField()
    iso_code = models.CharField(max_length=2, unique=True)

    def __unicode__(self):
        return self.name

    @staticmethod
    def with_artists():
        return Country.objects.annotate(number_of_artists=models.Count('artist')).filter(number_of_artists__gte=1)

class Artist(models.Model):
    name = models.TextField()
    mbid = models.TextField(unique=True)
    country = models.ForeignKey(Country)

Add Country.with_artists() to filter out countries without artists
Add Country.with_artists() to filter out countries without artists

  from django.db import models
  
  class Country(models.Model):
      name = models.TextField()
      iso_code = models.CharField(max_length=2, unique=True)
  
      def __unicode__(self):
          return self.name
  
+     @staticmethod
+     def with_artists():
+         return Country.objects.annotate(number_of_artists=models.Count('artist')).filter(number_of_artists__gte=1)
+ 
  class Artist(models.Model):
      name = models.TextField()
      mbid = models.TextField(unique=True)
      country = models.ForeignKey(Country)
  
Add Country.with_artists() to filter out countries without artists
## Code Before:
from django.db import models

class Country(models.Model):
    name = models.TextField()
    iso_code = models.CharField(max_length=2, unique=True)

    def __unicode__(self):
        return self.name

class Artist(models.Model):
    name = models.TextField()
    mbid = models.TextField(unique=True)
    country = models.ForeignKey(Country)

## Instruction:
Add Country.with_artists() to filter out countries without artists
## Code After:
from django.db import models

class Country(models.Model):
    name = models.TextField()
    iso_code = models.CharField(max_length=2, unique=True)

    def __unicode__(self):
        return self.name

    @staticmethod
    def with_artists():
        return Country.objects.annotate(number_of_artists=models.Count('artist')).filter(number_of_artists__gte=1)

class Artist(models.Model):
    name = models.TextField()
    mbid = models.TextField(unique=True)
    country = models.ForeignKey(Country)
