I'm using Django 1.6 and trying to make a field as a parent field and this parent field can have several children field?
I make a DB containing a drop down list contains (Computer, Scanner, Printer ) if the user choose a computer , he can added all things related to it such as monitor ..
is it possible to make it with Django?
Yes, it is possible. You need you use ForeignKey
for that task.
Example:
# models.py
from django.db import models
class Gadget(models.Model):
""" This is the model where you'll add gadgets like computer, printer, etc. """
name = models.CharField(max_length=100)
class Property(models.Model):
""" This is the model for adding monitor, etc. to the Gadgets models. """
gadget = models.ForeignKey(Gadget)
property = models.CharField(max_length=100)
something_else = models.CharField(max_length=100)
I'm using Django 1.6 and trying to make a field as a parent field and this parent field can have several children field?
I make a DB containing a drop down list contains (Computer, Scanner, Printer ) if the user choose a computer , he can added all things related to it such as monitor ..
is it possible to make it with Django?
Yes, it is possible. You need you use ForeignKey
for that task.
Example:
# models.py
from django.db import models
class Gadget(models.Model):
""" This is the model where you'll add gadgets like computer, printer, etc. """
name = models.CharField(max_length=100)
class Property(models.Model):
""" This is the model for adding monitor, etc. to the Gadgets models. """
gadget = models.ForeignKey(Gadget)
property = models.CharField(max_length=100)
something_else = models.CharField(max_length=100)
0 commentaires:
Enregistrer un commentaire