Hi Gerry.

Why do you use the many to many field for version in the project model ?
I think all you have to do is define the ForiegnKey as you did in the ProjectVersion model and it is enough . Because every project has many versions. Then you can get the versions of a projetc by writing :

p = Project()
versions = p.version_set()

and there you have versions as a list of all p's versions.

Yaron


Gerry Steele wrote:

I'm having a problem designing my data model. I'm sure there must be an elementary solution but I can't find it.

Below i have two models. ProjectVersion and Project. It all kind of works, however the admin "add" section for Project displays all rows for ProjectVersion in that field, instead of all the versions for just that Project. Is there a constraint or something i'm missing?

Many Thanks
Gerry


class ProjectVersion(models.Model):
        name = models.CharField(maxlength=30)
        released = models.NullBooleanField()
        release_date = models.DateField(blank = True, null=True)
        unnasigned = models.BooleanField()
        project_for_version = models.ForeignKey("Project")
        
        def __str__(self):
                return self.name
                
        class Admin:
                pass    
        
class Project(models.Model):
        name = models.CharField(maxlength=30)
        tag = models.CharField(maxlength=5)
        project_lead = models.ForeignKey(UserProfile)
        component = models.ForeignKey(ProjectComponent, blank=True, null=True)
        version = models.ManyToManyField(ProjectVersion, blank=True, null=True)
        
        def __str__(self):
                return self.name
        
        class Admin:
                pass



Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to