Hi all

I'm adding an XML mapping feature to Django db models.

The idea is to add as little XML mapping information as possible to existing 
models (such as: which fields get mapped to XML, what is their XPath...) in 
order to be able to automatically:
1. produce an XML representation of an object; 
2. parse a valid XML representation into a new object; and 
3. get an XSD schema of the model.

I'm well ahead. I have all three features working for some simple models. 
But I've hit a wall with regard to object relations, or ForeignKey fields.

Apparently any subclasses of ForeignKey are completely ignored by Django at 
runtime, even if they declare __metaclass__ = SubfieldBase

I guess they would need a special kind of metaclass, which I guess has not 
been written yet.

Can anybody help me understand what piece is failing?
How can I make it work?

-Tobia


Here is a (non) working example:

### test/models.py:

from django.db.models import *

# subclassing works for any simple field type, why not related fields?
class MyForeignKey(ForeignKey):
__metaclass__ = SubfieldBase

def __init__(self, *args, **kwargs):
ForeignKey.__init__(self, *args, **kwargs)

class TestSub(Model):
pass

class Test(Model):
sub = MyForeignKey(TestSub)

### shell:

>>> from test.models import Test, TestSub
>>> ts = TestSub.objects.create()
>>> t = Test.objects.create(sub=ts)
Traceback (most recent call last):
  ...
AttributeError: 'Test' object has no attribute 'sub_id'
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ENjhq8ZL_-AJ.
To post to this group, send email to django-users@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