0
最近、Rating
から継承する2つのモデルを作成しようとしましたが、 。私はこれが私のコードに衝突があってはならないと思われるので、不正な移行のためだと思いますか?私は最初にVenue
またはBand
という2つのオプションフィールドを持っていたRating
を持っていましたが、これはより良い構造だと感じています。クラス 'BandRating'のローカルフィールド 'created_at'と基底クラス 'Rating'の同じ名前のフィールドとの衝突
今後この種の問題に遭遇することなくこれを行う理想的な方法は何ですか?非抽象モデルから継承する場合それが不可能だ -
class Rating(models.Model, Activity):
created_at = models.DateTimeField(auto_now_add=True, null=True)
author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True)
rating = models.IntegerField(default=0)
description = models.CharField(max_length=200, null=True)
class Meta:
abstract = True
def get_author(self):
if self.author is None:
return "Anonymous"
else:
return self.author
@property
def activity_actor_attr(self):
return self.author
class BandRating(Rating):
band = models.ForeignKey(Band)
def __str__(self):
return str(self.band) + " rating"
class VenueRating(Rating):
venue = models.ForeignKey(Venue)
def __str__(self):
return str(self.venue) + " rating"
私のせい。乾杯 –