B
B
blackbb2015-11-22 20:42:48
Django
blackbb, 2015-11-22 20:42:48

How to change field value automatically after some time in django?

Couldn't formulate the question correctly. The point is the following. I am making a bulletin board website. There is a model:

class Hotel(models.Model):
    vip = models.BooleanField(default = False, verbose_name = 'VIP размещение')
    pay = models.DateField(verbose_name="День оплаты",default=datetime.now)
    on_off = models.BooleanField(default=False, blank=True, verbose_name="Включить обьявление")
    title = models.CharField(max_length=200, verbose_name="Название")
    slug = models.SlugField(unique=True, verbose_name="URL")
    category = models.ForeignKey(Category, verbose_name='Тип обьявления')
    image = models.ManyToManyField(MyImage,default = '', verbose_name="Фото")
    place = models.ForeignKey(Place, verbose_name='Место расположения')
    content = HTMLField(verbose_name='Информация')

Placements will be paid. The hotel will be placed after the field is True on. So the question is how to make it so that after the user has paid the amount, I turn on this field for him and after a month, a week or a year it turns off automatically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2015-11-26
@vintello

Disable: judging by the fact that the pay date field is just a date, then you just need a cron task that will run once a day for all ads and disable ads that have expired.
Enable: To enable immediately upon receipt of payment, use the post_save signal. If enabled the next day, include the logic in the same deactivation cron task. you just need to add a start date to the model

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question