views:

22

answers:

1

Hi guys, im want to know if there is any way to make a SlugField unique for Any field different to pub date?

for example i would like a slug unique (city field) for a field called country

any idea?

thanks

+4  A: 

Add a unique_together Meta option to your model class:

class MyModel(models.Model):
    city = models.SlugField()
    country = models.SlugField()
    class Meta:
        unique_together(('city', 'country'),)

For more information, see the documentation on unique_together.

Joseph Spiros