2

私のdjangoプロジェクトには、2つのバリエーションのユーザーがいます。1 つは django.auth の User クラスをサブクラス化し、2 番目はほぼ同じフィールドを使用しますが、実際のユーザーではありません (したがって、User から継承されません)。FieldUser クラス (フィールドのみを格納する) を作成し、RealUser サブクラスでは FieldUser と User の両方を作成する方法はありますが、FakeUser サブクラスでは FieldUser のみを作成する方法はありますか?

4

1 に答える 1

4

確かに、django モデルで多重継承を使用しましたが、問題なく動作します。

FieldUser の抽象クラスをセットアップしたいようです:

class FieldUser(models.Model):
    field1 = models.IntegerField()
    field2 = models.CharField() #etc
    class Meta:
        abstract=True #abstract class does not create a db table

class RealUser(FieldUser, auth.User):
    pass #abstract nature is not inherited, will create its own table to go with the user table

class FakeUser(FieldUser):
    pass #again, will create its own table
于 2010-06-23T18:47:08.417 に答える