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. Nested set abstraction for hierarchical data by lars.yencken 5 years ago
  2. Command to dump data as a python script by willhardy 4 years, 11 months ago
  3. SelfForeignKey to prevent hierarchical loops by jamesgpearce 3 years, 3 months ago
  4. Admin Apps Names Translation by Nad/ 3 years, 3 months ago
  5. i18n base model for translatable content by foxbunny 4 years, 10 months ago

Comments

(Forgotten your password?)