Thursday, June 30, 2016

initial costom field in modelform

hi everyone:

i defined tbls  customer and salesorder in my db, 
i want to show the customer name in my form but want not to save it in salesorder tbl,
how can i initial it for gui?
my code is :
#model
class Customer(models.Model):
name=models.CharField(max_length=40)
abbreviation=models.CharField(max_length=20)

class SalesOrder(models.Model):
customer=models.ForeignKey(Customer,related_name='by_customer',on_delete=models.CASCADE)

#form
class SalesOrderForm(forms.ModelForm):
customer_name=forms.CharField(required=False,widget=forms.TextInput(attrs={'readonly':''}))
class Meta:
model=SalesOrder
fields = ['customer','customer_name',]

thanks


1351552638@qq.com
 

No comments:

Post a Comment