Commits

Sergiy Kuzmenko committed a48dead

added model field docs

Comments (0)

Files changed (1)

+MODEL FIELDS
+------------
+
+
+SetField
+========
+
+SetField is a subclass of BiGintegerField that represents a set of values
+implemented as binary set. When initializing the caller must pass choices
+keyword argument whose values must be powers of 2.
+
+SetField is display friendly. The default widget for it is CheckboxSelectMultipleForSetField.
+
+In models.py:
+
+    from xdjango.db.models.fields import SetField
+    from django import models
+    
+    PIZZA = 1
+    PASTA = 2
+    SEAFOOD = 3
+    
+    class Restaurant:
+        name = models.TextField()
+        specialties = SetField(choices=((PIZZA,"pizza"),(PASTA,"pasta"),(SEAFOOD,"seafood")))
+
+Later on:
+
+    >>> joes = Restaurant()
+    >>> joes.name = "Joe's Finest"
+    >>> joes.specialties = PIZZA|PASTA
+    >>> joes.specialties
+    3
+    >>> joes.get_specialties_display()
+    "pizza, pasta"
+    
+
+
+
+WeekdaySetField
+===============
+
+A special field for storing week days. At the db level it is stored as string
+representing ordered values of ISO weekdays, e.g., "01" means "Monday and Tuesday"
+and "" for empty weekday set.
+    
+To limit weekday choices (e.g., if you need to make sure that only Monday
+to Friday are selectable), subclass WeekdaySetField and give it a custom
+weekday_choices attribute:
+    
+    MyWeekdaySetField(WeekdaySetField):
+        weekday_choices = my_weekday_choices
+