开发者

Slug unique for another field different to the pub date?

开发者 https://www.devze.com 2023-01-05 23:03 出处:网络
im want to know if there is any way to make a Slug开发者_C百科Field unique for Any field different to pub date?

im want to know if there is any way to make a Slug开发者_C百科Field 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消