hotkit / django-slumber

Slumber is a RESTful data connector that can be used to make proper RESTful data services from Django systems.
Boost Software License 1.0
49 stars 17 forks source link

Should RemoteForeignKey support NULL or empty value? #9

Open jsaytoe opened 11 years ago

jsaytoe commented 11 years ago

I want to have a model that contain RemoteForeignKey field and i want this field to be nullable. I got database initialize successfully but i also got error when i created an model instance via Django python shell.

KayEss commented 11 years ago

Can you show me what the field in the model looks like and what error you're getting? The code that produces the error would also help.

It should work the way that Django normally does it, using blank=True etc.

jsaytoe commented 11 years ago

My Model example is below: class Test(Model): customer = RemoteForeignKey(model_url='slumber://c_service/Customer/') payment = RemoteForeignKey(model_url='slumber://l_service/Payment/', null=True,blank=True)

when i created the Test model instance with only customer detail, i got the error as below:

import Test t_object = Test.objects.create(customer = "slumber://c_service/Customer/data/1/") Traceback (most recent call last): File "", line 1, in File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/manager.py", line 137, in create return self.get_query_set().create(_kwargs) File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/query.py", line 377, in create obj.save(force_insert=True, using=self.db) File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update) File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/base.py", line 551, in save_base result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw) File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/manager.py", line 203, in _insert return insert_query(self.model, objs, fields, _kwargs) File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/query.py", line 1593, in insert_query return query.get_compiler(using=using).execute_sql(return_id) File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 911, in execute_sql for sql, params in self.as_sql(): File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 872, in as_sql for obj in self.query.objs File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/fields/init.py", line 292, in get_db_prep_save prepared=False) File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/slumber/fields.py", line 37, in get_db_prep_value url = to_slumber_scheme(value._url, get_slumber_services()) AttributeError: 'NoneType' object has no attribute '_url'

I think we should take care on both get_prep_value and get_db_prep_value method in fields.py file for support null value

Hope this information help us to fix the issue