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

12 views
Skip to first unread message

Bovine Devine

unread,
Nov 24, 2014, 1:43:24 AM11/24/14
to django...@googlegroups.com
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?

François Schiettecatte

unread,
Nov 24, 2014, 6:32:25 AM11/24/14
to django...@googlegroups.com
Hi

You should consider having a single Barcodeid table and have a one-to-many relationship between the Hardwareid and Barcodeid.

François
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@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.

Reply all
Reply to author
Forward
0 new messages