models.py with django_dag models for parts hierarchy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.db import models
from django_dag.models import *
from django_dag import models as dag

Relationship=dag.edge_factory('parts.Part') #must specify appname (in this case: 'parts')

class Part(dag.node_factory(Relationship)):
    part_no = models.CharField(max_length=30, unique=True, db_index=True)
    description = models.TextField(null=True, blank=True)
    date_modified = models.DateTimeField(auto_now=True, auto_now_add=False, null=True, blank=True,)

    def __unicode__(self):
	return u'%s' % (self.part_no)

    class Meta:
        ordering = ['-date_modified']

class BillOfMaterial(models.Model):
    assembly = models.ForeignKey(Part, related_name='bom_assembly', db_index=False)
    subpart = models.ForeignKey(Part, related_name='bom_subpart', db_index=False)
    item = models.IntegerField(max_length=10, null=True, blank=True)
    qty = models.DecimalField(max_digits=10, decimal_places=5)
    order = models.IntegerField(max_length=10, null=True, blank=True)
    depth = models.IntegerField(max_length=10, null=True, blank=True)
 
    def __unicode__(self):
        return u'A:%s P:%s' % (self.assembly_no, self.subpart_no)

More like this

  1. pyserver -- runserver alias by presclark 5 years, 11 months ago
  2. Polymorphic inheritance ala SQLAlchemy by gsakkis 3 years, 6 months ago
  3. Complex Formsets, Redux by smagala 4 years, 1 month ago
  4. Wiki-like markup for sub templates by luckystarr 6 years, 7 months ago
  5. dumpdata/loaddata with MySQL and ForeignKeys by cmgreen 6 years, 3 months ago

Comments

(Forgotten your password?)