class Model(models.Model):
something1 = models.TextField(blank=True, null=True, default=None)
youknow = models.TextField(blank=True, null=True, default=None)
class Model2(models.Model):
example = models.ForeignKey(Model1)
something2 = models.TextField(blank=True, null=True, default=None)
def add_something(request):
primer = Models2.objects.create(example = "????", something2="text")
return redirect('/123')
def add_something(request):
# Создаём налету
primer = Model2.objects.create(example=Model1.create() , something2="text")
return redirect('/123')
def add_something(request):
# Достаём из базы данных существующую запись
model1 = Model1.objects.get(something1='something else', youknow='no matter')
primer = Model2.objects.create(example=model1, something2="text")
return redirect('/123')