他の回答では見たことのないものを追加したかっただけです。
Pythonクラスとは異なり、フィールド名の非表示は許可されていませんモデルの継承でて。
たとえば、次のようなユースケースで問題を実験しました。
私は、Djangoの認証を継承するモデルだったPermissionMixinを:
class PermissionsMixin(models.Model):
"""
A mixin class that adds the fields and methods necessary to support
Django's Group and Permission model using the ModelBackend.
"""
is_superuser = models.BooleanField(_('superuser status'), default=False,
help_text=_('Designates that this user has all permissions without '
'explicitly assigning them.'))
groups = models.ManyToManyField(Group, verbose_name=_('groups'),
blank=True, help_text=_('The groups this user belongs to. A user will '
'get all permissions granted to each of '
'his/her group.'))
user_permissions = models.ManyToManyField(Permission,
verbose_name=_('user permissions'), blank=True,
help_text='Specific permissions for this user.')
class Meta:
abstract = True
それから私は他のものの間、私はそれを上書きしたかった私のミックスインだったrelated_name
のgroups
フィールドを。だからそれは多かれ少なかれこのようでした:
class WithManagedGroupMixin(object):
groups = models.ManyToManyField(Group, verbose_name=_('groups'),
related_name="%(app_label)s_%(class)s",
blank=True, help_text=_('The groups this user belongs to. A user will '
'get all permissions granted to each of '
'his/her group.'))
私はこの2つのミックスインを次のように使用していました:
class Member(PermissionMixin, WithManagedGroupMixin):
pass
そうそう、私はこれがうまくいくと思っていましたが、うまくいきませんでした。しかし、私が得たエラーはモデルをまったく指していなかったため、問題はより深刻でした。何が問題になっているのかわかりませんでした。
これを解決しようとしているときに、ミックスインをランダムに変更して、抽象モデルのミックスインに変換することにしました。エラーは次のように変更されました。
django.core.exceptions.FieldError: Local field 'groups' in class 'Member' clashes with field of similar name from base class 'PermissionMixin'
ご覧のとおり、このエラーは何が起こっているのかを説明しています。
私の意見では、これは大きな違いでした:)