Look more on:
http://code.google.com/p/django-plus
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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
useful, but too complex for such simple task.
#
Yuri, tell me an easier way to make complex cross reference table forms (and grids also), please, will help me a lot :P
#
Please login first before commenting.