Reputation: 542
Hey friend i am competely new in django models . My question is, i have five table attributes like .
Rulno (integer)
From (IpAddressfield )
To(IpAddressfield )
Priority (integer)
Cisp(CharField)
Their can be many number of Priority and Cisp for a single Ruleno .so for i am writing model like .
class Ruleinfo(models.Model):
rule = models.IntegerField(null=False)
From = models.IPAddressField(null=True)
to = models.IPAddressField(null=True)
priority = models.ForeignKey('Priority',related_name = 'priority1')
Cisp =models.ForeignKey('Priority',related_name = 'cisp1')
def __unicode__(self):
return u'%s' %(self.rule)
class Priority(models.Model):
priority = models.IntegerField(null = True)
Ruleno = models.ForeignKey('Ruleinfo')
CISP = models.IntegerField(null = True)
def __unicode__(self):
return u'%s ' % (self.priority)
i am wondering, above model will fulfill my requirement or not ? .
or do let me know if any alternative is there .?
Upvotes: 0
Views: 1679
Reputation: 798626
The proper way to do it is with a ForeignKey
on the other end of the relation.
Upvotes: 6