Sunday, November 23, 2014

models.py question for setting up multiple sql entries for 1 master sql entry

Hello,

I am creating hardware database webapp in django and I have a question for how to setup my models.py to ensure I get the data entered into the mysql db that I have setup.

I have my models.py setup this way:

from django.db import models
from django.utils import timezone
# Create your models here.


class Hardwareid(models.Model):
hardwareid_text = models.CharField(max_length=200)
pub_date = models.DateField(default=timezone.now)
def __unicode__(self):             
return self.hardwareid_text
class Barcodeid1(models.Model):
barcode1 = models.ForeignKey(Hardwareid)
Barcodeid1_text = models.CharField(max_length=50)
def __unicode__(self):             
return self.Barcodeid1_text
class Barcodeid2(models.Model):
barcode2 = models.ForeignKey(Hardwareid)
Barcodeid2_text = models.CharField(max_length=50)
def __unicode__(self):             
return self.Barcodeid2_text


My question is do I have this setup properly? The end result I would like to have is to have a "master" Hardwareid name of an item in my sql db that has multiple barcodeids associated with each master hardwareid.

Is this the correct way to do it?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/47abd291-f46c-4d9b-b535-bd1ed0a7c6da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment