Base models¶
shopkit.core.basemodels
-
class
shopkit.core.basemodels.
AbstractCustomerBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Abstract base class for customers of the shop.
-
get_all_orders
()¶ Get all orders by the customer
-
get_confirmed_orders
()¶ Get all completed orders for this customer
Todo
We should consider adding a manager to
OrderBase
which can filter on the completed states.
-
get_latest_order
()¶ Return the lastest confirmed order
-
-
class
shopkit.core.basemodels.
AbstractPricedItemBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Abstract base class for items with a price. This only contains a get_price dummy function yielding a NotImplementedError. An actual price field is contained in the PricedItemBase class.
This is because we might want to get our prices somewhere else, ie. using some kind of algorithm, web API or database somewhere.
-
get_price
(**kwargs)¶ Get price for the current product.
This method _should_ be implemented in a subclass.
-
-
class
shopkit.core.basemodels.
ActiveItemBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Abstract base class for items which can be activated or deactivated.
-
class
shopkit.core.basemodels.
ActiveItemInShopBase
(*args, **kwargs)¶ Bases:
shopkit.core.basemodels.ActiveItemBase
This is a subclass of
ActiveItemBase
with anActiveItemManager
called in_shop returning only items with active=True.The main purpose of this class is allowing for items to be enabled or disabled in the shop’s backend.
-
class
shopkit.core.basemodels.
DatedItemBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Item for which the add and modification date are automatically tracked.
-
class
shopkit.core.basemodels.
NamedItemBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Abstract base class for items with a name.
-
class
shopkit.core.basemodels.
NumberedOrderBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Base class for Order with invoice and order numbers.
-
confirm
()¶ Make sure we set an invoice number upon order confirmation.
-
generate_invoice_number
()¶ Generates an invoice number for the current order. Should be overridden in subclasses.
-
generate_order_number
()¶ Generates an order number for the current order. Should be overridden in subclasses.
-
save
(*args, **kwargs)¶ Generate an order number upon saving the order.
-
-
class
shopkit.core.basemodels.
OrderedInlineItemBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
This base class does what, actually, order_with_respect_to should do but (for now) doesn’t implement very well: ordering of objects with a fk-relation to some class.
As we do not know what the class with the respective relation is, it is important to note that something like the following is added:
class MyOrderedInline(OrderedInlineItemBase): <related> = models.ForeignKey(RelatedModel) class Meta(OrderedInlineItemBase.Meta): unique_together = ('sort_order', '<related>') def get_related_ordering(self): return self.__class__.objects.filter(<related>=self.<related>) ... Or we could simply wait for the Django developers to fix `order_with_respect_to` once and for all. (Work in progress... See `Ticket #13 <http://code.djangoproject.com/ticket/13>`.)
-
static
get_next_ordering
(related)¶ Get the next ordering based upon the
QuerySet <django.db.models.QuerySet.QuerySet
with related items.
Get a
QuerySet <django.db.models.QuerySet.QuerySet
with related items to be considered for calculating the next sort_order.As we do not know in this base class what the related field(s) are, this raises a NotImplementedError. It should be subclassed with something like:
return self.objects.filter(<related>=self.<related>)
-
save
()¶ If no sort_order has been specified, make sure we calculate the it based on the highest available current sort_order.
-
static
-
class
shopkit.core.basemodels.
OrderedItemBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Abstract base class for items that have explicit ordering.
-
clean
()¶ If no sort_order has been specified, make sure we calculate the it based on the highest available current sort_order.
-
-
class
shopkit.core.basemodels.
PublishDateItemBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Item with a publish date.
-
class
shopkit.core.basemodels.
QuantizedItemBase
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Abstract base class for items with a quantity field.