Найти - Пользователи
Полная версия: Как правильно сделать связь: Многие ко многим.
Начало » Django » Как правильно сделать связь: Многие ко многим.
1
Kotakota
Привет.
Есть модели:
models.py
class PAttribute(models.Model):
cname = models.CharField(max_length=100)
surl = models.CharField(max_length=50)

class Profile(models.Model):
user = models.ForeignKey(User, unique=True)
pattribute = models.ManyToManyField(PAttribute)
Пытаюсь сохранить выполнить сохранение:
    # Добавляю запись в модель PAttribute
petite = PAttribute(cname='cname',surl='surl').save()
# Добавляю запись в модель профиля
profile = Profile(user=user,pattribute=petite)
profile.pattribute.add(petite)
profile.save()
Этот вариант не получается.
Пишет что то типа:
petite is not function argument

Как правильно добавить связь многие к одному?
thecore
Полагаю так
petite = PAttribute(cname='cname',surl='surl').save()
profile = Profile(user=user)
profile.pattribute.add(petite)
profile.save()
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB