Hi Bruno,

I have tried to save the roled model and got [AttributeError: 'Person
+Carpenter' object has no attribute 'person_ptr_id'] as in traceback
below.

In [1]: from carpenter.models import Person, Carpenter
In [2]: jack = Person(name='Jack')
In [3]: Carpenter(jack)
Out[3]: <Person+Carpenter: Person+Carpenter object>
In [4]: jack.chop()
Out[4]: 'chop, chop'
In [5]: jack.save()
parent = <class 'carpenter.models.Person'>, field =
<django.db.models.fields.related.OneToOneField object at 0x21a4a50>
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call
last)

/home/juacompe/projects/dci/trunk/<ipython console> in <module>()

/home/juacompe/.virtualenvs/dci/lib/python2.6/site-packages/
Django-1.2.3-py2.6.egg/django/db/models/base.pyc in save(self,
force_insert, force_update, using)
    432         if force_insert and force_update:
    433             raise ValueError("Cannot force both insert and
updating in model saving.")
--> 434         self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
    435
    436     save.alters_data = True

/home/juacompe/.virtualenvs/dci/lib/python2.6/site-packages/
Django-1.2.3-py2.6.egg/django/db/models/base.pyc in save_base(self,
raw, cls, origin, force_insert, force_update, using)
    474                 # this field). If so, fill it.

    475                 print 'parent = %s, field = %s' % (parent,
field)
--> 476                 if field and getattr(self,
parent._meta.pk.attname) is None and getattr(self, field.attname) is
not None:
    477                     setattr(self, parent._meta.pk.attname,
getattr(self, field.attname))
    478

AttributeError: 'Person+Carpenter' object has no attribute
'person_ptr_id'


The source code of the Person model and the Carpenter role can be
found in the link Ben gave above (http://www.google.com/url?
sa=D&q=http://groups.google.com/group/object-composition/browse_thread/
thread/fbb11a1e02b68de9&usg=AFQjCNFHv1njxL4B0SksOgPRFvj_hqhC0Q)

Any comments or suggestions would be really appreciated.

Thank you and best regards,
Chokchai Phatharamalai.

On Nov 23, 9:38 pm, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> On 23 nov, 13:08, Ben Scherrey <proteus...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> >     We are attempting to apply the concepts of Domain-Context
> > Interaction (DCI) to our python/django development. Unfortunately, the
> > metaclass mechanism which the main python library supporting this uses
> > conflicts with that of Django's metaclass for db.models. What happens
> > is that a metaclass and new methods are temporarily injected into the
> > model object while it acts as a role within a context. While it is an
> > instance of that role, we cannot use the save method on it. When the
> > role is removed the object may then be saved. Unfortunately that's
> > quite unsatisfactory and I'm wondering if Django's models can be a
> > little smarter when figuring out whether an object is a Django
> > db.model instance or not (we use multiple inheritance to retain the
> > db.model metaclass). Alternatively, can someone who gets more about
> > how the metaclass stuff is working with Django suggest a fix in the
> > roles module that would make it get along better with Django's ORM?
>
> >     roles can be found:http://pypi.python.org/pypi/roles/0.8
> >     thedcigroup (object composition) 
> > is:http://groups.google.com/group/object-composition
>
> >     some example code showing how to make it all "work" with django
> > is:http://groups.google.com/group/object-composition/browse_thread/threa...
>
> >    DCIis a very exciting architecture to me that extends the object
> > model &MVC/T to a more logical end and addresses a lot of complex
> > issues in design. The concepts have significantly altered my approach
> > to designing new systems. I really want to be able to make this work
> > cleanly with Django if at all possible. Appreciate any insights.
>
> Hi Ben.
>
> Could you post the full error message AND traceback you get when
> trying to save your "roled" model instance please ? Django models have
> a '._meta' attribute which stores, well, metadata about the model,
> like fields, tablename etc, so the author's assumption (exposed in the
> thread on the 'object-composition' group) that the problem is caused
> by a class name change doesn't stand. I currently lack time to dig
> into thisDCIthing and python-roles implementation but given enough
> context (=>traceback...) I might provide some hints.
>
> HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to