cypreess/django-plans — pull request #25 by dulaccc (2013-12-07 10:03:47+00:00)
Title: Customize models

I'm trying to customize `django-plans` models so that I can add support for vouchers through a dedicated `Voucher` model. But I don't want to include these into your project repo since it's too particular to this project in question.

More precisely, I'm trying to customize the behavior of the `Order.total` method, so that it can take into account associated vouchers through a foreign key.

To do that I've an idea on how to change current models layout that won't introduce backward compatibilities, like using abstract models for instance.
For example it would look like this :

**plans/abstract_models.py**
```python
from django.db import models

class AbstractOrder(models.Model):
STATUS=Enumeration([
(1, 'NEW', pgettext_lazy(u'Order status', u'new')),
...

class Meta:
abstract = True
```

**plans/models.py**
```python
from abstract_models import AbstractOrder

class Order(AbstractOrder):
pass
```

And then simply replace all references to the `Order` model by

```python
from django.db.models import get_model

Order = get_model('plans', 'order')
```

Then in my own project, if I create an app `plans` in my django project I will be able to override the Order model and the original `plans` app would reference the so called customized model.

**myproject/apps/plans/models.py**
```python
from plans.abstract_models import AbstractOrder

class Order(AbstractOrder):
discount_amount = models.DecimalField(_('discount amount'), max_digits=7, decimal_places=2)

def total(self):
amount = self.amount - self.discount_amount
if self.tax is not None:
return (amount * (self.tax + 100) / 100).quantize(Decimal('1.00'))
else:
return amount
```

Or maybe you have another way ?