I`m trying to create form field for Django admin backend In database it 
should be CharField field, contains "0" and "1" values with 24*7 length. In 
admin panels I want to see them as 7 fields with 24 checkboxes each. If 
checkbox is checked coressponding position of the string sets to "1", else 
"0".

model.py

from django.db import modelsfrom places.widgets import *from places.fields 
import *
class Place(models.Model):
    …
    time =          HoursWorkByWeekField()
    …

fields.py

from django.forms import fieldsfrom django.db import models
from places.widgets import HoursWorkByWeekWidget
class HoursWorkByWeekField(models.CharField):
    widget = HoursWorkByWeekWidget

    def __init__(self):
        super(HoursWorkByWeekField, self).__init__(max_length=24*7, 
min_length=24*7)

    def to_python(self, value):
        return list(value)

    def get_db_prep_value(self, value):
        result = []
        for i in range(24*7):
            if value[i] :
                result += ['1']
            else :
                result += ['0']
        return ''.join(result)

widgets.py

from django.forms import widgets
class HoursWorkByDayWidget(widgets.CheckboxSelectMultiple):
    def render(self, name, attrs=None):
        choices = range(0,24,1)
        return widgets.CheckboxSelectMultiple.render(self, name, attrs, choices)
class HoursWorkByWeekWidget(widgets.MultiWidget):
    def __init__(self, attrs=None):
        widgets = (
            HoursWorkByDayWidget(),
            HoursWorkByDayWidget(),
            HoursWorkByDayWidget(),
            HoursWorkByDayWidget(),
            HoursWorkByDayWidget(),
            HoursWorkByDayWidget(),
            HoursWorkByDayWidget(),
        )
        super(HoursWorkByWeekWidget, self).__init__(widgets, attrs)

When i try syncdb i have error:

TypeError: Error when calling the metaclass bases unhashable type: 'dict'

What am I doing wrong? How to organize code?
Many thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to