【问题标题】:Seeking Multiple-Form Table example in django在 django 中寻找多表格示例
【发布时间】:2011-10-19 07:22:29
【问题描述】:

我正在尝试在 django 中构建一个复杂的表格,可以将多个模型元素组合到一个 html 页面中。我正在寻找一些关于如何为单个模型元素构建页面的示例。 Filemaker 提供了此功能,但我无法忍受将其移植到 Filemaker 中。如果可能的话,我想使用 django。

例如,我建立了一个汽车销售模型。每个人都非常了解与购买汽车有关的多个领域。实际模型不是那么干净。在示例模型中,用户是销售人员。当用户登录时,他们会看到他们的客户屏幕。我没有让用户翻阅多个页面,而是尝试将大量相关数据放在一个页面上。

是否可以构建一个表单来执行此操作? django 提供什么吗 使这比构建大量自定义 html 表单更容易?有人知道类似的例子吗?

-----------我的布局--------------

<table>
  <tr><td> Top Left: Basic Customer info </td>
      <td> Top Right: Wish List info.  They want, but probably can't buy. </td>
      <td rowspan=2> A great big scrollable list of all customers </td>
  </tr>
  <tr><td>Bottom Left: Sales Person info about himself </td>
      <td>Bottom Right: A big notes section from the selected customer</td>
  </tr>
</table>

-----------我的模型--------------

# Bottom Left Panel
class SalesPersonProfile(models.Model):
  user = models.ForeignKey(User, unique=True)
  company = models.CharField(max_length=50, blank=True)
  addr = models.CharField(max_length=50, blank=True)
  city = models.CharField(max_length=25)
  state = models.CharField(max_length=2)
  zipCode = models.CharField(max_length=8)

# Top Left Panel Information
# Also a list of this stuff that goes in the extreme right
class Customer(models.Model):
  salesPerson = models.ForeignKey(User, editable = False) 
  lastName = models.CharField(max_length=20)
  firstName = models.CharField(max_length=20)
  address = models.CharField(max_length=50)
  city = models.CharField(max_length=25)
  state = models.CharField(max_length=2)
  zip = models.CharField(max_length=8)
  image = models.ImageField(upload_to='photos')

  # BOTTOM RIGHT - A great big multi-line notes field
  notes = models.TextField(null=True, blank=True)

#  Top Right Info
class WishList(models.Model):
  customer = models.ForeignKey(Customer, unique=True)
  dtg = models.DateTimeField('Date Added')
  carType = models.CharField(max_length=10, choices=CAR_TYPE)
  year = models.CharField(max_length=4)
  make = models.CharField(max_length=20)
  model = models.CharField(max_length=20)
  miles = models.CharField(max_length=20)
  color = models.CharField(max_length=20)

【问题讨论】:

    标签: django forms model


    【解决方案1】:

    尝试创建一个包含您需要的所有字段的表单,然后覆盖保存、验证等表单方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-25
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多