Я изменил регистрационный код Django. Я вставляю данные в модель UserProfile
и Business
во время регистрации.
Данные сохраняются в UserProfile
Модель.
#TODO: saving contact and address field data into UserProfile
user_profile = new_user.get_profile()
user_profile.user = new_user
user_profile.contact, user_profile.address = contact, kwargs['address']
user_profile.save()
Следующий код не работает. Получение этой ошибки.
'Business' instance needs to have a primary key value before a many-to-many relationship can be used.
#TODO: saving business field data into Business Model
user_business = Business()
user_business.owner = new_user
user_business.name = business
user_business.save()
спасибо
UPDATE
class Business(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField(max_length=100)
owner = models.ManyToManyField(User)
created = models.DateTimeField(editable=False, default=datetime.now)
modified = models.DateTimeField(editable=False, default=datetime.now)
class Meta:
ordering = ['name']
def save(self):
self.modified = datetime.now()
if not self.slug:
self.slug = slugify(self.name, instance=self)
super(Business, self).save()