Tôi đang sử dụng django-userena
. Tôi có một mô hình được gọi là UserProfile
. Tôi đã thêm các trường bổ sung trong biểu mẫu đăng ký. và Các trường này được hiển thị chính xác nhưng dữ liệu không được lưu. Tôi cũng muốn lưu một số trường dữ liệu vào một Mô hình khác (Business
). Ví dụ: tôi có hai trường như contact
và business
. Tôi muốn trường liên hệ sẽ chuyển đến trường UserProfile
Kiểu và business
sẽ chuyển đến Business Model
. bất kỳ đầu mối? Cảm ơn bạnthêm các trường bổ sung vào các hình thức django-userena
Đây là mã của tôi
class SignupFormExtra(SignupForm):
address = forms.CharField(label=_(u'Address'),max_length=30,required=False)
contact = forms.CharField(label=_(u'Contact'),max_length=30,required=False)
business = forms.CharField(label=_(u'Business Name'),max_length=30,required=False)
def save(self):
"""
Override the save method to save the first and last name to the user
field.
"""
user_profile = super(SignupFormExtra, self).save(commit=False)
user_profile.address = self.cleaned_data['address']
user_profile.contact = self.cleaned_data['contact']
user_profile.business = self.cleaned_data['business']
user_profile.save()
return user_profile
UPDATE: Tôi đang lưu trữ những giá trị về một trường hợp tài ... Tôi muốn toe lưu trữ chúng trong Tiểu sử trên mô hình - một ví dụ đó là ràng buộc để người dùng
Bạn đã thử nó trong phương pháp sạch hình thức không? – Ahsan