Django Admin interface with pickled set

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2011-01-16T00:58:06Z Indexed on 2011/01/16 1:53 UTC
Read the original article Hit count: 517

I have a model that has a pickled set of strings. (It has to be pickled, because Django has no built in set field, right?)

class Foo(models.Model):

    __bar = models.TextField(default=lambda: cPickle.dumps(set()), primary_key=True)

    def get_bar(self):
        return cPickle.loads(str(self.__bar))

    def set_bar(self, values):
        self.__bar = cPickle.dumps(values)

    bar = property(get_bar, set_bar)

I would like the set to be editable in the admin interface. Obviously the user won't be working with the pickled string directly. Also, the interface would need a widget for adding/removing strings from a set.

What is the best way to go about doing this? I'm not super familiar with Django's admin system. Do I need to build a custom admin widget or something?

Update: If I do need a custom widget, this looks helpful: http://www.fictitiousnonsense.com/archives/22

© Stack Overflow or respective owner

Related posts about python

Related posts about django