diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-06-09 15:52:35 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-06-09 15:52:35 +0200 |
commit | 253759d5bd43158f75386b0935da9a58cced024b (patch) | |
tree | fac8f6216b0bca2a573ca3f6df9986a308fc79bf /ishtar/furnitures/models.py | |
parent | 53bf03b4801527dbb442fe3e22a3f66605891d9a (diff) | |
download | Ishtar-253759d5bd43158f75386b0935da9a58cced024b.tar.bz2 Ishtar-253759d5bd43158f75386b0935da9a58cced024b.zip |
"Shadow" the base item in forms - creation and modification (closes #445)
Diffstat (limited to 'ishtar/furnitures/models.py')
-rw-r--r-- | ishtar/furnitures/models.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py index db8773ad4..02c3661a5 100644 --- a/ishtar/furnitures/models.py +++ b/ishtar/furnitures/models.py @@ -28,6 +28,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext from django.db.utils import DatabaseError from django.utils.safestring import SafeUnicode from django.db.models import Q, Max +from django.db.models.signals import m2m_changed from django.contrib.auth.models import User from django.contrib.gis.db import models @@ -298,7 +299,7 @@ class Address(BaseHistorizedItem): address_complement = models.TextField(_(u"Address complement"), null=True, blank=True) postal_code = models.CharField(_(u"Postal code"), max_length=10, null=True, - blank=True) + blank=True) town = models.CharField(_(u"Town"), max_length=30, null=True, blank=True) country = models.CharField(_(u"Country"), max_length=30, null=True, blank=True) @@ -868,7 +869,6 @@ class BaseItem(BaseHistorizedItem, OwnPerms): self.index, self.context_record.label, self.label)]) - class Item(BaseHistorizedItem, OwnPerms): TABLE_COLS = ['base_items.context_record.parcel.town', 'base_items.context_record.parcel.operation.year', @@ -926,6 +926,25 @@ class Item(BaseHistorizedItem, OwnPerms): base_item.save() super(Item, self).save(*args, **kwargs) +""" +def initialize_item(sender, **kwargs): + # initialize base items with the item + if kwargs['action'] != 'post_add': + return + item = kwargs['instance'] + # item already initialized + if item.label: + return + base_items = item.base_items.all() + if len(base_items) != 1: + return + base_item = base_items[0] + item.label = base_item.label + item.description = base_item.description + item.save() +m2m_changed.connect(initialize_item, + sender=Item.base_items.through) +""" class ParcelOwner(LightHistorizedItem): owner = models.ForeignKey(Person, verbose_name=_(u"Owner")) |