Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 62b999a7fe
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 32 lines (20 sloc) 0.766 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import datetime
from django.db import models

class ArrayField(models.CharField):
    
    __metaclass__ = models.SubfieldBase
    
    
    description = "basic field for storing string arrays"
    def __init__(self, *args, **kwargs):
        kwargs['max_length'] = 200
        super(ArrayField, self).__init__(*args, **kwargs)
        
    def to_python(self, value):
        if isinstance(value, list):
            return value
        
        return value.split('|')
    
    def get_prep_value(self, value):
        return '|'.join(value)
    

# Create your models here.
class Talk(models.Model):
    topic = models.CharField(max_length=200)
    when = models.DateTimeField()
    tags = ArrayField(max_length=200)
    duration = models.FloatField()
    
    
Something went wrong with that request. Please try again.