【发布时间】:2013-06-13 17:00:10
【问题描述】:
我有以下现有代码可以使用(我只包括了相关部分)。
models.py
class Customer(models.Model):
customer_id = models.CharField(primary_key=True, max_length=16)
account_phone = PhoneNumberField(null=True, blank=True, max_length=255)
display_phone = PhoneNumberField(null=True, blank=True, max_length=255)
.
.
.
customer.py
@render_to('customer/edit.html')
def edit(request, customer_id):
customer = Customer.objects.get(customer_id=customer_id)
if not request.POST:
return dict(form=CustomerForm(instance=customer))
submit = request.POST.copy()
submit['customer_id'] = customer.customer_id
form = CustomerForm(submit, instance=customer)
if not form.is_valid():
return dict(form=form)
_f = form.save(commit=False)
_f.save()
class CustomerForm(ModelForm):
.
.
.
def __init__(self, *args, **kwargs)
super(CustomerForm, self).__init__(*args, **kwargs)
.
.
class Meta:
model = Customer
我需要向 CustomerForm 添加一个名为 assigned_numbers 的查询,这将允许我从 account_phone 和 display_phone 获取与 customer_id 关联的电话号码。我被困在如何正确运行查询上,非常感谢任何建议。如果我需要提供更多信息,请告诉我。
【问题讨论】: