Question

I am creating a website were user can subscribe packages for one month (Pretty much the same as newsletter subscription 5$/month). how can i manage these subscription packages. whether i need to delete the item permanently after the expiration date? what is the best method.

models.py

class avail_packs(models.Model):
    pack_name = models.CharField(max_length=100)
    pack_description = models.TextField()
    pack_duration_days = models.IntegerField(default=0)
    pack_cost = models.IntegerField(default=0)      

class selected_packs(models.Model):
    user = models.ForeignKey(User)
    pack = models.ForeignKey(avail_packs)
    activation_date = models.CharField(max_length=100)        
    quantity = models.IntegerField(default=0)

assume there is a pack say bronze

pack_name=bronze
pack_description='1000 newsletters'
pack_duration_days=30
pack_cost=9.9$

if user activated a pack

user= User.objects.get(username='suhail')
pack= avail_packs.objects.get(pack_name=bronze)
activation_date= 27-aug-2013
quantity=1

now my question is what i want to do the item in selected pack on date 26-sep-2013?

do i need to delete the item(delete item from selected_packs where today-activation_date>29).

if i want to delete the item then how?

do i need to run a cron(django celery) and check every day to delete these items.

or do i need to delete the item when user clicked the newletter(or some chargable items)

i am using paypal so is there any method in paypal to do these types of monthly subscriptions?

Was it helpful?

Solution

Running celery for such a simple task is oversized. Take a look at django management commands and run a cronjob every night to deactivate/delete packages.

from optparse import make_option

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--delete',
            action='store_true',
            dest='delete',
            default=False,
            help='Delete inactive packages'),
        )

    def handle(self, *args, **options):

        if options['delete']:
            selected_packs.objects.filter(activation_date__lt=timeframe).delete()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top