我可以使用以下现有代码(我仅包含相关部分)。
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)
.
.
.
客户.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。我对如何正确运行查询感到困惑,不胜感激任何建议。如果我需要提供更多信息,请告诉我。
哔哔one
相关分类