"Concrete class" for schema ?

24 views
Skip to first unread message

matthieu

unread,
Mar 24, 2015, 4:40:24 AM3/24/15
to django...@googlegroups.com
I am trying to use django multiselectfield w/ django-hstore and having a hard time with schema class implementation.

As I understand the doc the schema "class" key accepts a class (not an instance).

So my setup :
# Model
class CField(models.Model):
[...]
    data = hstore.DictionaryField(schema=[
            {
                'name': 'lieux',
                'class': getattr(multiselectfield, 'MultiSelectField'),
                'kwargs': {
                    'blank': True,
                    'max_length': 100,
                    'choices':(
                        ('salle_fetes','Salle des fêtes'),
                        ('hotel','hôtel'),
                        ('bar','bar'),
                        ('Pub','pub')
                      )
                }
            },
[.....]

# Form
class CFieldForm(forms.ModelForm):
    class Meta:
        model = items_models.CField


# Python shell

ipdb> mycustomfields
<CField: CField object>

ipdb> type(mycustomfields)
<class 'pilot.core.items.models.CField'>

ipdb> mycustomfields._hstore_virtual_fields
{u'inscription': <django_hstore.virtual.VirtualField: inscription>, u'lieux': <django_hstore.virtual.VirtualField: lieux>, u'text': <django_hstore.virtual.VirtualField: text>, u'choice': <django_hstore.virtual.VirtualField: choice>, u'char': <django_hstore.virtual.VirtualField: char>, u'email': <django_hstore.virtual.VirtualField: email>}


MY PROBLEM

ipdb> form = forms.CFieldForm(instance=mycustomfields)
*** KeyError: u'lieux'

Ok, but 'lieux' is in the virtual fields ? Where am I wrong ?


matthieu

unread,
Mar 24, 2015, 4:42:18 AM3/24/15
to django...@googlegroups.com
I did not mentionned it but I correctly import multiselectfield

Nemesis

unread,
Mar 24, 2015, 2:14:33 PM3/24/15
to django...@googlegroups.com
Hi matthieu,

is MultiSelectField a string based field?

Implementing new fields involves digging in the django internals (models, forms, ecc).

There's no easy answer.

Federico
--
You received this message because you are subscribed to the Google Groups "django-hstore" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-hstor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages