Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 2.36 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Problems with submit button in change_form template Django
  2. class Product(models.Model):
  3.     product_name= models.CharField(max_length=50)
  4.     price = models.DecimalField(max_digits=10, decimal_places=2, default=Decimal('0.00'))
  5.     tax_per_item = models.DecimalField(max_digits=10, null=True, blank=True, decimal_places=2, default=Decimal('0.00'))
  6.     discount_per_item = models.DecimalField(max_digits=10, null=True, blank=True, decimal_places=2, default=Decimal('0.00'))
  7.  
  8.  
  9. class Order(models.Model):
  10.     produks = models.ManyToManyField(Product, verbose_name=u"Kode Produk")
  11.     no_customer = models.ForeignKey(Customer, null=True, blank=True, related_name='%(class)s_kode_cust')
  12.  
  13.     def order_view(request):
  14.         if 'enter' in request.POST:
  15.             #response to tabular.html template
  16.             return HttpResponseRedirect('/admin/POS/Pemesanan/inline')
  17.  
  18. class Foo(models.Model):
  19.     product = models.ForeignKey(Product, editable=False)
  20.     pemesanan = models.ForeignKey(Order)
  21.     quantity = models.IntegerField()
  22.     price = models.IntegerField()
  23.     discount = models.IntegerField()
  24.     tax = models.IntegerField()
  25.        
  26. class PemesananAdmin(admin.ModelAdmin):
  27. fieldsets = (
  28.     ('Customer in Time (Person)', {
  29.         'fields': ('no_customer',),
  30.     }),
  31.     ('Date', {
  32.         'fields' : ('date', 'delivery_date',),
  33.     }),
  34.     ('Order Details', {
  35.         'fields' : ('produks',),
  36.     }),
  37. )
  38. search_fields = ['produks', 'no_customer']
  39. raw_id_fields = ('produks', 'no_customer',)
  40. related_lookup_fields = {
  41. 'fk': ['no_customer'],
  42. 'm2m': ['produks'],
  43. }
  44. inlines = [
  45.     FooInline,
  46. ]
  47.  
  48. class FooInline(admin.TabularInline):
  49. model = Foo
  50. template = 'admin/POS/Pemesanan/inline/tabular.html'
  51. extra = 0
  52. allow_add = True
  53.        
  54. {% extends "admin/change_form.html" %}
  55. {% block after_field_sets %}{{ block.super }}
  56.  
  57. <form action="" method="post">
  58. <input type="submit" name="enter" value="Enter" />
  59. </form>
  60. {% endblock %}
  61.        
  62. <form action="" method="post">
  63. <input type="submit" name="enter" value="Enter" />
  64. </form>
  65.        
  66. class Product(models.Model):
  67.    ...
  68.  
  69. class Order(models.Model):
  70.    products = models.ManyToManyField(Product, through='Item')
  71.  
  72. class Item(models.Model):
  73.    order = models.ForeignKey(Order)
  74.    product = models.ForeignKey(Product)
  75.    quantity = models.IntegerField()
  76.    ...
  77.        
  78. class ItemInline(admin.TabularInline):
  79.     model = Item
  80.  
  81. class OrderAdmin(admin.ModelAdmin):
  82.     inlines = (ItemInline,)