0

I'm working with Django 1.7.2 with generic relation (reason: project has two databases), and after import I don't want to have overwritten database.

I want to show only active season

Here is my model, is overwritten after import:

class Season(models.Model):
    name = models.CharField('Name', max_length=255)
    start = models.DateField('Start')
    end = models.DateField('End')

    def __unicode__(self):
        return self.name

In another place in models.py file I create Generic relation to another model (SaleAndCycle) in another database:

def extend_models(sender, **kwargs):
    if sender._meta.app_label != 'extend':
        return
    def set_stati(self, database='extend', save=True):
        online_before = self.online
        self.online = True
        for flag in self.flags:
            if flag.flag == 'offline':
                self.online = False
        if save and self.online != online_before:
            self.save(using=database)

    for name, name_singular, name_plural in (
        ('Season', 'Season', 'Seasons'):
        if sender.__name__ == name:
            sender._meta.verbose_name = name_singular
            sender._meta.verbose_name_plural = name_plural
    if sender.__name__ == 'Season':
        sender.add_to_class('sale_and_cycles', generic.GenericRelation(SaleAndCycle))
        sender.add_to_class('is_sale_active', property(
            lambda o: o.sale_and_cycles.using('default')))
        sender.add_to_class('is_cyclic_event_active', property(
            lambda o: o.sale_and_cycles.using('default')))
        sender.add_to_class('cycle_link', property(
            lambda o: o.sale_and_cycles.using('default')))

I want to show all active Seasons for not login user:

def get_queryset(self):
    seasons = Season.objects.all()
    if not self.request.user.is_superuser:
        all_seasons = Season.objects.filter(events_isactiveflags__is_active=True)
        print all_seasons

I get error:

no such table: events_isactiveflag

But this table exists in my database.

Mark
  • 15
  • 1
  • 6

2 Answers2

1

by the line of code

Season.objects.filter(events_isactiveflags__is_active=True)

here events_isactiveflags__is_active=True means events_isactiveflags is a table and is_active is a column of the table. So no such table found named events_isactiveflags . if you are trying to get active sessions you can try this code

Session.objects.filter(expire_date__gte=timezone.now())
0

delete db and once again run syncdb

sam
  • 29
  • 2