These are chat archives for django/django

21st
Nov 2015
Ivan Lukyanets
@1vank1n
Nov 21 2015 06:42

Hi, everybody!

For example, i have models:

class Robot(models.Model):
    left_hand_weapon = models.ForeignKey('Weapon')
    right_hand_weapon = models.ForeignKey('Weapon')

class Weapon(models.Model):
    title = models.CharField(max_length=50)

Is it real to create one form for save new Robot with 2 weapons?.... So create 3 instances (1 Robot, 2 Weapon) with one form.

If it's real, so how can i do this?

agus makmun
@agusmakmun
Nov 21 2015 06:54
@1vank1n maybe like this?
class Robot(models.Model):
    left_hand_weapon = models.ForeignKey('Weapon')
    right_hand_weapon = models.ForeignKey('Weapon')

class Weapon(models.Model):
    property = models.ForeignKey(Robot, related_name='weapon')
    title = models.CharField(max_length=50)
Ivan Lukyanets
@1vank1n
Nov 21 2015 06:56
@agusmakmun you right! my mistake).. but how to save it in one form.. i still don't know (
I add. The idea is to be able to put 2 new Weapons to create a Robot.
agus makmun
@agusmakmun
Nov 21 2015 07:01
may use chain
Ivan Lukyanets
@1vank1n
Nov 21 2015 07:02
@agusmakmun hmm... how?... can you give a link? I will be read about it.
Batur
@Batur24
Nov 21 2015 17:46
hey, everyone!