English 中文(简体)
帮助在集延戈采用涉及示范形式的方案拟订模式
原标题:Help with a programming pattern in django that involves model forms

我的问题是很长时间的,因为我对良好方案拟订做法,特别是詹戈缺乏了解。 我赞赏任何建议。

www.un.org/Depts/DGACM/index_spanish.htm 模型(简化)

class Customer(models.Model):
    # Customer info
    first_name = models.CharField(max_length=75)
    last_name  = models.CharField(max_length=179, null=True, blank=True)
    # ... and more fields that need validation but not needed for the question
    pay_method          = models.CharField(max_length=1, choices=PAY_METHODS)
    bank_code           = models.CharField(max_length=4, blank=True, null=True)
    bank_office_code    = models.CharField(max_length=4, blank=True, null=True)
    bank_control_digit  = models.CharField(max_length=2, blank=True, null=True)
    bank_account_number = models.CharField(max_length=10, blank=True, null=True)

class Product(models.Model):
    name = models.CharField(max_length=50)

class Subscription(models.Model):
    customer = models.ForeignKey(Customer)
    product  = models.ForeignKey(Product)
    user     = models.OneToOneField(User)
    # ...
    start_date = models.DateField(null=True)
    end_date   = models.DateField(null=True)
    # ...
    is_main_subscription = models.BooleanField(default=False)

class Invoice(models.Model):
    customer = models.ForeignKey(Customer)
    subscriptions = models.ManyToManyField(Subscription,null=True,blank=True)
    #...

www.un.org/Depts/DGACM/index_spanish.htm 问题

有两个非常相似的订阅过程。 一个是新用户,另一个是现有用户。

对于新用户来说,订阅过程涉及填写客户的个人数据和在客户表格中支付信息,并至少设定一个说明。 每一处都指产品。 这一过程结束时,产生了对所有这些说明的发票。 我认为,这里不必采用“发票”模式,但我认为,如果该模式有用的话,我会在这里这样做。 每一处都设有一个连接网关的用户。

第一个说明是主要订阅<>。 与这一规定相关的用户可以延长或取消其他订阅,并购买新的订阅。 这一新过程涉及在必要时改变付款信息,但没有客户的个人数据。 我们必须区分新的规定。

<>>Forms

客户一号为三种模式:

支付 表格仅供用户在订阅过程中使用。

class PaymentForm(forms.ModelForm):
    class Meta:
        model = Customer
        fields = (
             pay_method ,
             bank_code ,
             bank_office_code ,
             bank_control_digit ,
             bank_account_number 
        )
    # ...

DataForm is used alone for logged in users whose subscription is the main subscription to edit the Customer personal info out of the subscription process.

class DataForm(forms.ModelForm):
    class Meta:
        model = Customer
        fields = (
             first_name ,
             last_name ,
            # All the other fields
        )
    # ...

NewCustomer 表格为我设计了一种组合支付表格和数据表格的形式。

class NewCustomerForm(MyDataForm, PaymentForm):
    class Meta:
        model = Customer
        fields = MyDataForm.Meta.fields + PaymentForm.Meta.fields

说明 我认为,应该有两种形式(在线表格):

  • RenewalsFormSet: For logged in users to cancel or renew existing subscriptions. User can t edit info, only cancel or renew.
  • SubscriptionsFormSet: For logged and not logged in users, to add new subscriptions.

How could I handle both cases in the simplest way? The new subscriptions formset must not have knowledge of existing subscriptions.

www.un.org/Depts/DGACM/index_spanish.htm 问题在于。

从Django的观点来看,订阅过程是:

  1. GET form view: Forms are presented to the user.
  2. POST forms: Forms are validated. If error: go to point 1. If success: save POST data in the session.
  3. GET confirmation view: Summary of products to be purchased.
  4. GET confirm payment: Depending of the pay method selected the process here may vary.
  5. GET thankyou page

What can I do to have a single subscription process for both logged and not logged in users?

我曾想到某种物体,如一个黑色箱,接收客户(根据用户是否已经登记)的投入和回报,所有用户都愿意储存在数据库中。

但我不知道如何这样做。

(如果你看上去,你必须非常 n。) 感谢!

最佳回答

我看不出你如何把“黑箱”模型与你现有的数据模型相匹配。

你们都需要做的是,视用户是否已经订阅而改变其形式。 如果你也就表格写出一种节省费用的方法,即更新外部网关,以更新b,那么这种看法将完全相同。

难道在你被打上了什么位置?

问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...