これはどのように見えるかの例です。それは返すsqlall
class UserConnectionRequest(models.Model):
sender = models.ForeignKey(UserProfile, related_name='sent_requests')
recipient = models.ForeignKey(UserProfile, related_name='received_requests')
connection_type = models.PositiveIntegerField(verbose_name=_(u'Connection type'), \
choices=UserConnectionType.choices())
class Meta:
unique_together = (("sender", "recipient", "connection_type"),)
実行:あなたはモデルを持っていることを前提とし
CONSTRAINT をusers_userconnectionrequest_sender_id_2eec26867fa22bfa_uniq:このモデルは適切にDBに同期されている場合には、ユニーク制約(postgresの)を持っている
CREATE TABLE "users_userconnectionrequest" (
"id" serial NOT NULL PRIMARY KEY,
"sender_id" integer NOT NULL REFERENCES "users_userprofile" ("id") DEFERRABLE INITIALLY DEFERRED,
"recipient_id" integer NOT NULL REFERENCES "users_userprofile" ("id") DEFERRABLE INITIALLY DEFERRED,
"connection_type" integer,
UNIQUE ("sender_id", "recipient_id", "connection_type")
)
UNIQUE(sender_id、recipient_id、connection_type)、
文書はdbレベルで強制されていると言いますが、これで十分でしょうか? :) – shanyu
うーん、リンクできますか?私は見ましたが、それを見ませんでした。たとえそうであっても、sqlall出力のどこで実行されるのか分かりません。 – jMyles
ここにあります:https://docs.djangoproject.com/en/dev/ref/models/options/#django.db.models.Options.unique_together – shanyu