U
U
un1t2015-07-06 13:58:26
Django
un1t, 2015-07-06 13:58:26

Django - how to implement object moderation?

It seems that the directive has an example of such a case.
The user creates an ad, sends it for moderation, the moderator accepts it, it starts showing.
Next, the user decided to fix something, for example, an ad test. Edited and sent for moderation. Moreover, the old version is still shown in the search, and the new one is being moderated.
Those. somewhere information about the object is stored, and somewhere about its edited copy, which is being moderated.
How it is better to implement it?
Through two independent models? Through model inheritance? Maybe with one model by adding some attribute. Then copies will be stored in the same table. Maybe there are other options?
Option 1: One table

class Banner(models.Model):
    name = models.CharField()
    text = models.CharField()
    image = models.ImageField()
    original = models.ForeignKey('self')  # если не None, значит это копия
    moderation_status = modes.IntegerField()

Option 2: two independent models
class Banner(models.Model):
    name = models.CharField()
    text = models.CharField()
    image = models.ImageField()

class ModerationBanner(models.Model):
    name = models.CharField()
    text = models.CharField()
    image = models.ImageField()
    moderation_status = modes.IntegerField()

Option 3: Inheritance
class BaseBanner(models.Model):
    name = models.CharField()
    text = models.CharField()
    image = models.ImageField()

class Banner(BaseBanner):
   pass

class ModerationBanner(BaseBanner):
   original = models.ForeignKey(Banner) 
   moderation_status = modes.IntegerField()

If you solved a similar problem, which option did you use?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
van2048, 2015-07-06
@un1t

As an option - store multiple versions of the ad. Show the last moderated in the search (for example, by timestamp). The rest may be hard to follow in the future.

MODERATION_STATUS_CHOICES = (
        (0, _('Not moderated')),
        (1, _('moderated')),
    )

class Banner(models.Model):
    user = models.ForeignKey(User, related_name='banner_user') # в зависимости от случая объявление можно привязать к другой сущности
    #место для других полей, которые не меняются для объявления

class BannerDetail(models.Model):
    banner = models.ForeignKey(Banner, related_name='bannerdetail_banner')
    name = models.CharField()
    text = models.CharField()
    image = models.ImageField()
    moderation_status = modes.IntegerField(choices=MODERATION_STATUS_CHOICES, default=0)
    time_stamp = models.DateTimeField(auto_now=True)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question