May be Group should include packages of specific versions: class Group(models.Model): name = models.CharField(max_length=100) product = models.ForeignKey(Product) -packages = models.ManyToManyField(Package) +packages = models.ManyToManyField(PackageVersion)
class Profile(models.Model): name = models.CharField(max_length=100) businessversion = models.ForeignKey(BusinessVersion) lifecyclestage = models.ForeignKey(LifecycleStage) group = models.ForeignKey(Group) -packageversions = models.ManyToManyField(PackageVersion) So: for package in profile.profile.group.packages.all(): print package.package.name print package.version And what is BusinessVersion I didn't understand. On Nov 28, 4:59 pm, Jonathan <jonathan.kin...@gmail.com> wrote: > Hi, > > I've slimmed it down to the relevant fields. I'm a bit of a noob, but > I think I'm basically trying to build a generic framework that can be > made specific in a profile. > > Profile = BusinessVersion + Group + LifecycleStage + Package.Versions > > Jonathan > > class Product(models.Model): > name = models.CharField(max_length=20) > > class BusinessVersion(models.Model): > version = models.CharField(max_length=10) > description = models.CharField(max_length=100) > product = models.ForeignKey(Product) > > class LifecycleStage(models.Model): > name = models.CharField(max_length=40) > sequence = models.DecimalField(max_digits=2, decimal_places=0) > > class Package(models.Model): > name = models.CharField(max_length=100) > > class PackageVersion(models.Model): > version = models.CharField(max_length=10) > package = models.ForeignKey(Package) > lifecyclestage = models.ForeignKey(LifecycleStage) > > class Group(models.Model): > name = models.CharField(max_length=100) > product = models.ForeignKey(Product) > packages = models.ManyToManyField(Package) > > class Profile(models.Model): > name = models.CharField(max_length=100) > businessversion = models.ForeignKey(BusinessVersion) > lifecyclestage = models.ForeignKey(LifecycleStage) > group = models.ForeignKey(Group) > packageversions = models.ManyToManyField(PackageVersion) > > class Stream(models.Model): > name = models.CharField(max_length=4) > businessversion = models.ForeignKey(BusinessVersion) > > On Nov 29, 1:19 am, t0ster <tost...@gmail.com> wrote: > > > > > Could you post your models.py code here? > > > On Nov 28, 1:10 pm, Jonathan <jonathan.kin...@gmail.com> wrote: > > > > This may be more of a general database design question, but I want to > > > come up with something that works with Django's ORM. > > > > I have four bits of information that I want to link together. Generic > > > packages, package versions, groups of packages and a profile that > > > brings them together. > > > > The final goal is a Profile that binds the Packages from a Group to > > > specific Versions. > > > > I have a solution at the moment but it seems a bit clumsy for what > > > seems like something that would be commonly encountered. > > > > 4 models: Package, Version, Group and Profile. I've omitted the id > > > primary key column on the examples. > > > > Package: > > > | name | > > > -- > > > | django | > > > | python | > > > > Version: > > > | package_id | version | > > > -- > > > | 1 | 1.0 | > > > | 1 | 1.1 | > > > | 2 | 2.4 | > > > | 2 | 2.6 | > > > > Group: > > > | name | > > > -- > > > | django_stack | > > > > group_packages: > > > | group_id | package_id | > > > -- > > > | 1 | 1 | > > > | 1 | 2 | > > > > Profile: > > > | name | group_id | > > > -- > > > | django_prod | 1 | > > > | django_dev | 1 | > > > > profile_packageversion: > > > | profile_id | version_id | > > > -- > > > | 1 | 1 | > > > | 1 | 2 | > > > | 2 | 3 | > > > | 2 | 4 | > > > > I can get what I need from a two step process, but is this the best or > > > most direct way to achieve this? > > > > for package in profile.group.packages.all(): > > > print package.name > > > for version in package.versions.all(): > > > print version > > > > Is there a nicer way to do this? Is there a different model structure > > > that I could use? > > > > Jonathan -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.