Changeset - dba37736362d
[Not reviewed]
0 1 1
Christopher Neugebauer - 8 years ago 2016-04-06 12:59:00
chrisjrn@gmail.com
Adds db indices
2 files changed with 72 insertions and 4 deletions:
0 comments (0 inline, 0 general)
registrasion/migrations/0012_auto_20160406_1212.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
# Generated by Django 1.9.2 on 2016-04-06 12:12
 
from __future__ import unicode_literals
 

	
 
from django.db import migrations, models
 

	
 

	
 
class Migration(migrations.Migration):
 

	
 
    dependencies = [
 
        ('registrasion', '0011_auto_20160401_0943'),
 
    ]
 

	
 
    operations = [
 
        migrations.AlterField(
 
            model_name='cart',
 
            name='active',
 
            field=models.BooleanField(db_index=True, default=True),
 
        ),
 
        migrations.AlterField(
 
            model_name='cart',
 
            name='released',
 
            field=models.BooleanField(db_index=True, default=False),
 
        ),
 
        migrations.AlterField(
 
            model_name='cart',
 
            name='time_last_updated',
 
            field=models.DateTimeField(db_index=True),
 
        ),
 
        migrations.AlterField(
 
            model_name='category',
 
            name='order',
 
            field=models.PositiveIntegerField(db_index=True, verbose_name='Display order'),
 
        ),
 
        migrations.AlterField(
 
            model_name='product',
 
            name='order',
 
            field=models.PositiveIntegerField(db_index=True, verbose_name='Display order'),
 
        ),
 
        migrations.AlterField(
 
            model_name='productitem',
 
            name='quantity',
 
            field=models.PositiveIntegerField(db_index=True),
 
        ),
 
        migrations.AlterIndexTogether(
 
            name='cart',
 
            index_together=set([('active', 'released'), ('released', 'user'), ('active', 'user'), ('active', 'time_last_updated')]),
 
        ),
 
    ]
registrasion/models.py
Show inline comments
...
 
@@ -96,12 +96,13 @@ class Category(models.Model):
 
        blank=True,
 
        help_text=_("If enabled, a user must select an "
 
                    "item from this category."),
 
    )
 
    order = models.PositiveIntegerField(
 
        verbose_name=("Display order"),
 
        db_index=True,
 
    )
 
    render_type = models.IntegerField(
 
        choices=CATEGORY_RENDER_TYPES,
 
        verbose_name=_("Render type"),
 
        help_text=_("The registration form will render this category in this "
 
                    "style."),
...
 
@@ -144,12 +145,13 @@ class Product(models.Model):
 
        verbose_name=_("Reservation duration"),
 
        help_text=_("The length of time this product will be reserved before "
 
                    "it is released for someone else to purchase."),
 
    )
 
    order = models.PositiveIntegerField(
 
        verbose_name=("Display order"),
 
        db_index=True,
 
    )
 

	
 

	
 
@python_2_unicode_compatible
 
class Voucher(models.Model):
 
    ''' Registration vouchers '''
...
 
@@ -310,12 +312,13 @@ class VoucherDiscount(DiscountBase):
 
    cart. '''
 

	
 
    voucher = models.OneToOneField(
 
        Voucher,
 
        on_delete=models.CASCADE,
 
        verbose_name=_("Voucher"),
 
        db_index=True,
 
    )
 

	
 

	
 
class IncludedProductDiscount(DiscountBase):
 
    ''' Discounts that are enabled because another product has been purchased.
 
    e.g. A conference ticket includes a free t-shirt. '''
...
 
@@ -455,23 +458,39 @@ class RoleEnablingCondition(object):
 

	
 
@python_2_unicode_compatible
 
class Cart(models.Model):
 
    ''' Represents a set of product items that have been purchased, or are
 
    pending purchase. '''
 

	
 
    class Meta:
 
        index_together = [
 
            ("active", "time_last_updated"),
 
            ("active", "released"),
 
            ("active", "user"),
 
            ("released", "user"),
 
        ]
 

	
 
    def __str__(self):
 
        return "%d rev #%d" % (self.id, self.revision)
 

	
 
    user = models.ForeignKey(User)
 
    # ProductItems (foreign key)
 
    vouchers = models.ManyToManyField(Voucher, blank=True)
 
    time_last_updated = models.DateTimeField()
 
    time_last_updated = models.DateTimeField(
 
        db_index=True,
 
    )
 
    reservation_duration = models.DurationField()
 
    revision = models.PositiveIntegerField(default=1)
 
    active = models.BooleanField(default=True)
 
    released = models.BooleanField(default=False)  # Refunds etc
 
    active = models.BooleanField(
 
        default=True,
 
        db_index=True,
 
    )
 
    released = models.BooleanField(
 
        default=False,
 
        db_index=True
 
    )  # Refunds etc
 

	
 
    @classmethod
 
    def reserved_carts(cls):
 
        ''' Gets all carts that are 'reserved' '''
 
        return Cart.objects.filter(
 
            (Q(active=True) &
...
 
@@ -489,13 +508,13 @@ class ProductItem(models.Model):
 
    def __str__(self):
 
        return "product: %s * %d in Cart: %s" % (
 
            self.product, self.quantity, self.cart)
 

	
 
    cart = models.ForeignKey(Cart)
 
    product = models.ForeignKey(Product)
 
    quantity = models.PositiveIntegerField()
 
    quantity = models.PositiveIntegerField(db_index=True)
 

	
 

	
 
@python_2_unicode_compatible
 
class DiscountItem(models.Model):
 
    ''' Represents a discount-product-quantity relation in a Cart. '''
 

	
0 comments (0 inline, 0 general)