django-plus cross table usage example

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# models.py

from djangoplus.cross_table import CrossTableManager

class Division(models.Model):
    item = models.ForeignKey(Item)
    customer = models.ForeignKey(Customer)
    quantity = models.DecimalField(max_digits=6, decimal_places=1)

    objects = CrossTableManager()

#------------------------

# forms.py

from djangoplus.cross_table import CrossTableForm

class FormDivision(CrossTableForm):
    class Meta:
        model = Division
        x_model = Item
        y_model = Customer
        x_field = 'item'
        y_field = 'customer'

    class InfoFields: # Additional fields
        product_name = forms.Field(required=False, widget=forms.TextInput)

    class CrossFields:
        quantity = forms.Field(required=False, widget=forms.TextInput)

# views.py

    formcross_division = FormDivision(
        x_values=Item.objects.all(),
        y_values=Customer.objects.all(),
        queryset=Division.objects.all(),
    )

# template

<html>
<head>
    {{ formcross_dividida.media }}
</head>
<body>
    <table>
        {{ formcross_division }}
    </table>
</body>
</html>

More like this

  1. Protect anti robots template tag by marinho 5 years, 11 months ago
  2. Jcrop Form by mjthie 3 years, 3 months ago
  3. MultiSelectField with comma separated values (Field + FormField) by quinode 1 year, 11 months ago
  4. (Almost) Single table polymorphism in Django by julkiewicz 3 years ago
  5. Converting a Flickr Datetime to a Python Datetime by obeattie 7 years, 1 month ago

Comments

buriy (on April 24, 2009):

useful, but too complex for such simple task.

#

marinho (on May 6, 2009):

Yuri, tell me an easier way to make complex cross reference table forms (and grids also), please, will help me a lot :P

#

(Forgotten your password?)