Python 如何使用unique_中的外键字段一起进行验证?

Python 如何使用unique_中的外键字段一起进行验证?,python,django,django-rest-framework,foreign-keys,Python,Django,Django Rest Framework,Foreign Keys,此模型数据将从django默认管理端添加。 在此图像中显示了管理员视图。 我试图使锦标赛日期、锦标赛时间和比赛类型必须是唯一的条目 比赛日期和比赛类型在MTournament表中 比赛时间在Mtournament\u时间表中 这就是我如何在Mtournament_时间表中一起实现unique_的方法 共同唯一=['mtournament\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu比赛日期','mtournament\uuuuuuuuuuuuuuuuu

此模型数据将从django默认管理端添加。 在此图像中显示了管理员视图。 我试图使锦标赛日期、锦标赛时间和比赛类型必须是唯一的条目

比赛日期和比赛类型在MTournament表中 比赛时间在Mtournament\u时间表中 这就是我如何在Mtournament_时间表中一起实现unique_的方法

共同唯一=['mtournament\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu比赛日期','mtournament\uuuuuuuuuuuuuuuuuuuuuuuuuuu


这回答了你的问题吗?
class BaseClass(models.Model):
    is_active
    insert_date
    updated_date


class Game(BaseClass):
    # is_active, insert_date, updated_date
    # name, game_image
    name = models.CharField(max_length=16)
    game_image = models.ImageField(upload_to='game_images/', default='game_images/game_default.jpg')


class GameMap(BaseClass):
    # is_active, insert_date, updated_date
    game = models.ForeignKey(Game, on_delete=models.SET_NULL, null=True)
    name = models.CharField(max_length=64)


class Tournament(BaseClass):
    CHECK = (
        ("No", "NO"),
        ("Yes", "YES"),
    )
    MATCH_TYPE = (
        ("Solo", "SOLO"),
        ("Duo", "DUO"),
        ("Squad", "SQUAD"),
    )
    # is_active, insert_date, updated_date
    # game, name, tournament_date, map, match_type, camera_type, country, country_base
    game = models.ForeignKey(Game, on_delete=models.SET_NULL, null=True)
    name = models.CharField(max_length=64)
    tournament_image = models.ImageField(upload_to='esports/tournament', default='esports/user/default.png')
    country = models.ForeignKey(Country, on_delete=models.SET_NULL, null=True, default=99) 
    country_base = models.CharField(choices=CHECK, max_length=8, default='NO')


class MTournament(BaseClass):
    MATCH_TYPE = (
        ("Solo", "SOLO"),
        ("Duo", "DUO"),
        ("Squad", "SQUAD"),
    )
    # is_active, insert_date, updated_date
    # tournament, mtournament_date, map, match_type
    tournament = models.ForeignKey(Tournament, on_delete=models.SET_NULL, null=True)
    tournament_date = models.DateField(verbose_name='Tournament Date')
    map = models.ForeignKey(GameMap, on_delete=models.SET_NULL, null=True)
    match_type = models.CharField(choices=MATCH_TYPE, max_length=32, default=1)
   

class Mtournament_Time(BaseClass):
    # is_active, insert_date, updated_date
    mtournament = models.ForeignKey(MTournament, on_delete=models.SET_NULL, null=True)
    tournament_time = models.TimeField(verbose_name='Multiple Tournament Time')

    class Meta:
        db_table = 'tbl_mtournament_time'
        verbose_name = "Tournament Time"
        # Below is the code i want to check
        unique_together = ['mtournament__tournament_date', 'mtournament__match_type', 'tournament_time']